using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Validation; using System.Text.Json; var root = Path.GetFullPath(args.Length > 0 ? args[0] : "ESP_00VB_Livrables"); var output = new List(); foreach (var path in Directory.GetFiles(root).Where(p => new[]{".docx",".dotx",".xlsx",".pptx"}.Contains(Path.GetExtension(p)))) { try { using OpenXmlPackage doc = Path.GetExtension(path) switch { ".xlsx" => SpreadsheetDocument.Open(path,false), ".pptx" => PresentationDocument.Open(path,false), _ => WordprocessingDocument.Open(path,false) }; var validator = new OpenXmlValidator(FileFormatVersions.Microsoft365); var errors = validator.Validate(doc).Select(e => new {description=e.Description,path=e.Path?.XPath,part=e.Part?.Uri.ToString()}).ToArray(); output.Add(new {file=Path.GetFileName(path),errors}); } catch(Exception ex){output.Add(new {file=Path.GetFileName(path),exception=ex.Message});} } var json = JsonSerializer.Serialize(output,new JsonSerializerOptions {WriteIndented=true}); File.WriteAllText(Path.Combine(Path.GetDirectoryName(root)!,"_fabrication_00VB","schema_validation.json"),json); Console.WriteLine("Validation enregistrée : " + output.Count + " fichiers.");