我使用适用于 Microsoft Office 的 Open XML SDK 2.0 生产力工具:http:
//www.microsoft.com/downloads/en/details.aspx? FamilyID=c6e744e5-36e9-45f5-8d8c-331df206e0d0&displaylang=en
当我想做这些事情的时候。只需启动生产力工具,加载包含您想要的内容的 .docx,然后让该工具为您生成代码。
我刚刚做了一个例子,这是它生成的代码:
using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml;
....
public Paragraph GenerateParagraph()
{
Paragraph paragraph1 = new Paragraph(){ RsidParagraphAddition = "00EA7FFB", RsidParagraphProperties = "00EA7FFB", RsidRunAdditionDefault = "00EA7FFB" };
ParagraphProperties paragraphProperties1 = new ParagraphProperties();
ParagraphStyleId paragraphStyleId1 = new ParagraphStyleId(){ Val = "ListParagraph" };
NumberingProperties numberingProperties1 = new NumberingProperties();
NumberingLevelReference numberingLevelReference1 = new NumberingLevelReference(){ Val = 0 };
NumberingId numberingId1 = new NumberingId(){ Val = 2 };
numberingProperties1.Append(numberingLevelReference1);
numberingProperties1.Append(numberingId1);
paragraphProperties1.Append(paragraphStyleId1);
paragraphProperties1.Append(numberingProperties1);
Run run1 = new Run();
Text text1 = new Text(){ Space = SpaceProcessingModeValues.Preserve };
text1.Text = "Item ";
run1.Append(text1);
paragraph1.Append(paragraphProperties1);
paragraph1.Append(run1);
return paragraph1;
}
这是使用 OpenXml 标头,而不是专门使用 Word