Bonjour,
J'utilise les librairies
pour créer un document .docx en c#.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 using DocumentFormat.OpenXml; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing;
J'ai recopié telle quelle la fonction de msdn :
J'ai bien un fichier .docx de généré mais impossible de l'ouvrir. J'ai une erreur qui me dit que le contenu est incorrect et en détaillant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 public static void CreateWordprocessingDocument(string filepath) { // Create a document by supplying the filepath. using (WordprocessingDocument wordDocument = WordprocessingDocument.Create(filepath, WordprocessingDocumentType { // Add a main document part. MainDocumentPart mainPart = wordDocument.AddMainDocumentPart(); // Create the document structure and add some text. mainPart.Document = new Document(); Body body = mainPart.Document.AppendChild(new Body()); Paragraph para = body.AppendChild(new Paragraph()); Run run = para.AppendChild(new Run()); run.AppendChild(new Text("Create text in body - CreateWordprocessi } }
"un document doit contenir un seul element racine", "erreur dans document.xml ligne 1". "document.xml" est vide...
Si qn a une idée... Merci d'avance
Partager