If you don't want to play or feel lazy dealing directly with this xml, then here comes a special SDK for Open XML from Microsoft, called
. This provides a set of strongly typed .Net classes and a XML tool for use with open xml.
to start playing with this new amazing developer friendly document format.
1: using DocumentFormat.OpenXml.Wordprocessing;
2: using DocumentFormat.OpenXml;
3:
4: namespace GeneratedCode
5: {
6: public class GeneratedClass
7: {
8: // Creates an Document instance and adds its children.
9: public Document GenerateDocument()
10: {
11: Document document1 = new Document() { MCAttributes = new MarkupCompatibilityAttributes() { Ignorable = "w14 wp14" } };
12: document1.AddNamespaceDeclaration("wpc", "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas");
13: document1.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
14: document1.AddNamespaceDeclaration("o", "urn:schemas-microsoft-com:office:office");
15: document1.AddNamespaceDeclaration("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships");
16: document1.AddNamespaceDeclaration("m", "http://schemas.openxmlformats.org/officeDocument/2006/math");
17: document1.AddNamespaceDeclaration("v", "urn:schemas-microsoft-com:vml");
18: document1.AddNamespaceDeclaration("wp14", "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing");
19: document1.AddNamespaceDeclaration("wp", "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing");
20: document1.AddNamespaceDeclaration("w10", "urn:schemas-microsoft-com:office:word");
21: document1.AddNamespaceDeclaration("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
22: document1.AddNamespaceDeclaration("w14", "http://schemas.microsoft.com/office/word/2010/wordml");
23: document1.AddNamespaceDeclaration("wpg", "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup");
24: document1.AddNamespaceDeclaration("wpi", "http://schemas.microsoft.com/office/word/2010/wordprocessingInk");
25: document1.AddNamespaceDeclaration("wne", "http://schemas.microsoft.com/office/word/2006/wordml");
26: document1.AddNamespaceDeclaration("wps", "http://schemas.microsoft.com/office/word/2010/wordprocessingShape");
27:
28: Body body1 = new Body();
29:
30: Paragraph paragraph1 = new Paragraph() { RsidParagraphAddition = "006D0D97", RsidRunAdditionDefault = "00334C80",
ParagraphId = "2DC4F30E", TextId = "77777777" };
31:
32: Run run1 = new Run() { RsidRunProperties = "00334C80" };
33:
34: RunProperties runProperties1 = new RunProperties();
35: Bold bold1 = new Bold();
36: Italic italic1 = new Italic();
37:
38: runProperties1.Append(bold1);
39: runProperties1.Append(italic1);
40: Text text1 = new Text();
41: text1.Text = "H";
42:
43: run1.Append(runProperties1);
44: run1.Append(text1);
45:
46: Run run2 = new Run();
47: Text text2 = new Text() { Space = SpaceProcessingModeValues.Preserve };
48: text2.Text = "ello ";
49:
50: run2.Append(text2);
51:
52: Run run3 = new Run() { RsidRunProperties = "00334C80" };
53:
54: RunProperties runProperties2 = new RunProperties();
55: Bold bold2 = new Bold();
56: Italic italic2 = new Italic();
57:
58: runProperties2.Append(bold2);
59: runProperties2.Append(italic2);
60: Text text3 = new Text();
61: text3.Text = "W";
62:
63: run3.Append(runProperties2);
64: run3.Append(text3);
65:
66: Run run4 = new Run();
67: Text text4 = new Text();
68: text4.Text = "orl";
69:
70: run4.Append(text4);
71: BookmarkStart bookmarkStart1 = new BookmarkStart() { Name = "_GoBack", Id = "0" };
72: BookmarkEnd bookmarkEnd1 = new BookmarkEnd() { Id = "0" };
73:
74: Run run5 = new Run();
75: Text text5 = new Text();
76: text5.Text = "d";
77:
78: run5.Append(text5);
79:
80: paragraph1.Append(run1);
81: paragraph1.Append(run2);
82: paragraph1.Append(run3);
83: paragraph1.Append(run4);
84: paragraph1.Append(bookmarkStart1);
85: paragraph1.Append(bookmarkEnd1);
86: paragraph1.Append(run5);
87:
88: SectionProperties sectionProperties1 = new SectionProperties() { RsidR = "006D0D97" };
89: PageSize pageSize1 = new PageSize() { Width = (UInt32Value)12240U, Height = (UInt32Value)15840U };
90: PageMargin pageMargin1 = new PageMargin() { Top = 1440, Right = (UInt32Value)1440U, Bottom = 1440, Left = (UInt32Value)1440U,
Header = (UInt32Value)720U, Footer = (UInt32Value)720U, Gutter = (UInt32Value)0U };
91: Columns columns1 = new Columns() { Space = "720" };
92: DocGrid docGrid1 = new DocGrid() { LinePitch = 360 };
93:
94: sectionProperties1.Append(pageSize1);
95: sectionProperties1.Append(pageMargin1);
96: sectionProperties1.Append(columns1);
97: sectionProperties1.Append(docGrid1);
98:
99: body1.Append(paragraph1);
100: body1.Append(sectionProperties1);
101:
102: document1.Append(body1);
103: return document1;
104: }
105: }
106: }