Bonjour
Je dois générer des docx mais mes templates sont en .doc.
Est ce que c'est possible et comment ou sinon existe t'il un utilitaire qui pourra transformer mes .doc en template docx?
Merci de votre aide
Version imprimable
Bonjour
Je dois générer des docx mais mes templates sont en .doc.
Est ce que c'est possible et comment ou sinon existe t'il un utilitaire qui pourra transformer mes .doc en template docx?
Merci de votre aide
Bonjour,
Avec ce qui suit tu peut "transformer" un .doc en .docx, référence juste Microsoft.Office.Interop.Word
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 private void ConvertDocToDocx(string docFilePath, string outputDocxFilePath) { Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); app.Visible = false; var doc = OpenDocument(app, docFilePath, false); SaveDocAsDocx(app, doc, outputDocxFilePath); app.Quit(ref ObjectConstants.False, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue); } private void SaveDocAsDocx(Microsoft.Office.Interop.Word.Application app, Microsoft.Office.Interop.Word.Document doc, object outputFilePath) { object format = WdSaveFormat.wdFormatXMLDocument; doc.SaveAs(ref outputFilePath, ref format, ref ObjectConstants.False, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue); } private Microsoft.Office.Interop.Word.Document OpenDocument(Microsoft.Office.Interop.Word.Application app, object filePath, bool visible) { var doc = (Microsoft.Office.Interop.Word.Document)app.Documents.Open(ref filePath, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue, ref ObjectConstants.MissingValue); if (!visible) { doc.ActiveWindow.Visible = false; } return doc; } public class ObjectConstants { public static Object MissingValue = Missing.Value; public static Object True = true; public static Object False = true; }
Merci mais j'ai oublier un petit détail, je dois assigner le contenu du .doc dans un String pour des modifications et ensuite le passer en docx.
Et dans ton code je ne vois pas ou il faudrait que j'insère le contenu dans un string.