After adding one document to another I need properly refresh numbering value.
For example:
In Doc1 we have
- Ddddddddd
- Ffffffff
- Ttttttttt
On the end of the Doc1 I have bookmark “test”
In Doc2 we have
- Kkkkkkk
- Ooooooooo
- mmmmmmmmm
After adding Doc2 to Doc1 I am expecting to have numbering 1, 2, 3, 4, 5
But I got result: 1, 2, 3, 1, 1, 1
Could you please help me to solve the problem?
And this is the my test code:
Document doc1 = new Document(templatePath + "Doc1.doc");
Document doc2 = new Document(templatePath + "Doc2.doc");
InsertDocumentAtBookmark("test", doc1, doc2);
doc.Save(@"c:\out.doc");
And this code from Aspose:
public void InsertDocumentAtBookmark(string bookmarkName, Document dstDoc, Document srcDoc)
{
// Create DocumentBuilder
DocumentBuilder builder = new DocumentBuilder(dstDoc);
// Move cursor to bookmark and insert paragraph break
builder.MoveToBookmark(bookmarkName);
builder.Writeln();
// Content of srcdoc will be inserted after this node
Node insertAfterNode = builder.CurrentParagraph.PreviousSibling;
// Content of first paragraph of srcDoc will be apended to this parafraph
Paragraph insertAfterParagraph = (Paragraph) insertAfterNode;
// Content of last paragraph of srcDoc will be apended to this parafraph
Paragraph insertBeforeParagraph = builder.CurrentParagraph;
// We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.ParentNode;
// Loop through all sections in the source document.
foreach(Section srcSection in srcDoc.Sections)
{
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach(Node srcNode in srcSection.Body)
{
// Do not insert node if it is a last empty paragarph in the section.
Paragraph para = srcNode as Paragraph;
if ((para != null) && para.IsEndOfSection && !para.HasChildNodes)
break;
// If current paragraph is first paragraph of srcDoc
// then append its content to insertAfterParagraph
if (para.Equals(srcDoc.FirstSection.Body.FirstParagraph))
{
foreach(Node node in para.ChildNodes)
{
Node dstNode = dstDoc.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting);
insertAfterParagraph.AppendChild(dstNode);
}
}
// If current paragraph is last paragraph of srcDoc
// then append its content to insertBeforeParagraph
else if (para.Equals(srcDoc.LastSection.Body.LastParagraph))
{
Node previouseNode = null;
foreach(Node node in para.ChildNodes)
{
Node dstNode = dstDoc.ImportNode(node, true, ImportFormatMode.KeepSourceFormatting);
if (previouseNode == null)
insertBeforeParagraph.InsertBefore(dstNode, insertBeforeParagraph.FirstChild);
else
insertBeforeParagraph.InsertAfter(dstNode, previouseNode);
previouseNode = dstNode;
}
}
else
{
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = dstDoc.ImportNode(srcNode, true, ImportFormatMode.KeepSourceFormatting);
// Insert new node after the reference node.
dstStory.InsertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
}
Thanks,
Rudolf