本文共 1045 字,大约阅读时间需要 3 分钟。
Creating a new document using (WordProcessingMLDocument myDoc =
WordProcessingMLDocument.Open(@"C:/myDoc.docx"))
{
Paragraph paragraph = myDoc.Body.Paragraphs.New();
paragraph.AddText("Hello World!");
myDoc.Save();
}
Insert a custom XML file using (WordProcessingMLDocument myDoc =
WordProcessingMLDocument.Open(@"C:/myDoc.docx"))
{
myDoc.CustomXml.Add(@"C:/customXML.xml");
}
Import a paragraph from a document using (WordProcessingMLDocument sourceDoc =
WordProcessingMLDocument.Open(@"C:/source.docx"))
using (WordProcessingMLDocument targetDoc =
WordProcessingMLDocument.Open(@"C:/target.docx"))
{
Paragraph paragraph = sourceDoc.Body.Paragraphs ;
targetDoc.Body.Insert(paragraph);
targetDoc.Save();
}
Move a paragraph inside the document to a specific location (after the third table in this sample)
using (WordProcessingMLDocument myDoc =
WordProcessingMLDocument.Open(@"C:/myDoc.docx"))
{
Paragraph paragraph = myDoc.Body.Paragraphs ;
Table table = myDoc.Body.Tables ;
myDoc.Body.Paragraphs.InsertAfter(
paragraph, table);
myDoc.Save();
}
转载地址:http://mrkpi.baihongyu.com/