Hello,
how can I copy the content of a document including styles (as a block) and add it to another document as a numeric list?
Thanks for your efforts
Best regards
dirk
//Load source document
Document doc = new Document();
doc.LoadFromFile("test.docx");
//Create a new document and add a section
Document newdoc = new Document();
Section newsec = newdoc.AddSection();
foreach (Section sec in doc.Sections)
{
foreach (DocumentObject obj in sec.Body.ChildObjects)
{
//Copy the source document to newdoc
newdoc.Sections[0].Body.ChildObjects.Add(obj.Clone());
}
}
foreach(DocumentObject obj1 in newsec.Body.ChildObjects)
{
if(obj1 is Paragraph)
{
//set numeric list
Paragraph para = obj1 as Paragraph;
para.ListFormat.ApplyNumberedStyle();
}
}
//Save the newdoc
newdoc.SaveToFile("result.docx");