I’m trying to create a new document from multiple existing documents and I think I am doing it wrong.
I started with a huge document containing multiple chapters and subchapters (not sections). Then I splitted this document in single chapters and subchapters. Each chapter and subchapter is stored in a single file (docx). I did this by deleting all other chapters form the main document and then saving the rest. So I have an array of multiple files all with the same styles.
Then I use a simple construct in vb.net to iterate through these documents and combine them to a singe document.
Dim targetfile = DocumentModel.load("firstChapter.docx") For i = 2 To UBound(ArrayOfFiles)- 1 Dim Source = DocumentModel.Load(ArrayOfFiles(i)) targetfile.Content.End.InsertRange(Source.Content) Next targetfile.Save("someName.docx")
On the first glance every thing is fine and lightnig fast (compared to native VBA).
when opening “someName.docx” behind every document, added by “content.end.insert” there is a new (floating) section.
there are plenty of new styles (heading 1_1, heading 1_2, heading 1_3 etc.) and from the second imported document on, the heading styles are not numbered any more.
Is there any way to
- insert a new document to an existing document without creating a new section
- with preserving the existiing styles
Thank you very much for your tips.