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[ 1];
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[1];
Table table = myDoc.Body.Tables[3];
myDoc.Body.Paragraphs.InsertAfter(
paragraph, table);
myDoc.Save();
}

Last edited Aug 24, 2006 at 1:25 PM by Wouterv, version 7

Comments

No comments yet.