Hello,
I like to insert two files (in attachment) which contain heading.
The first contains :
- Heading Level 1 (Doc 1)
1.1 Heading Level 2 (Doc 1)
1.1.1 Heading Level 3 (Doc 1)
The second contains:
1.1.1 Heading Level 3 (Doc 2)
1.1.1.1 Heading Level 4 (Doc 2)
1.1.1.1.1 Heading Level 5 (Doc 2)
2. Heading Level 1 (Doc 2)
2.1. Heading Level 2 (Doc 2)
I use the insertDocument provided in your documentation (with the ImportFormatMode.USE_DESTINATION_STYLES to have no duplication of styles).
Document doc1 = new Document(new File("D:\File1.doc").getAbsolutePath());
Document doc1Clone = doc1.deepClone();
DocumentBuilder builder = new DocumentBuilder(doc1Clone);
Document wordDoc = new Document(new File("D:\File2.doc").GetAbsolutePath());
insertDocument(builder.getCurrentParagraph(), wordDoc);
doc1Clone.save("D:\output.docx");
And the result is a mix of the two documents. (See output.docx)
Have I done something wrong ?
I use the version 11.5 of Aspose.Java.
Regards.
Hi Roseline,
Thanks for your query. You have not change the position of cursor by using DocumentBuilder. Please use the following code snippet and find the output file in attachment.
Document doc1 = new Document(new File("D:\\ File1.doc").getAbsolutePath());
Document doc1Clone = doc1.deepClone();
DocumentBuilder builder = new DocumentBuilder(doc1Clone);
Document wordDoc = new Document(new File("D:\\ File2.doc").getAbsolutePath());
builder.moveToBookmark("Bmk");
insertDocument(builder.getCurrentParagraph(), wordDoc);
Bookmark bmk = doc1Clone.getRange().getBookmarks().get("Bmk");
bmk.setText("");
bmk.remove();
doc1Clone.save("D:\\ output.docx");
Please let us know if you have any more queries.
Hi,
Thanks for your answer.
Thanks to the bookmark located in the end of the first document, then the documentBuilder can go to the last paragraph.
But if the first file has no ‘ending’ bookmark ?
How can I do ?
Thanks in advance for your support.
Regards.
Thank you Tahir,
With another topic, you gave me the solution.
Instead of use builder.moveTo(“Bmk”), I can do builder.moveToDocumentEnd().
Regards.
Hi Roseline,
Yes, you can use moveToDocumentEnd() if you have not bookmark at the end of document. Please let us know if you have any more queries.