Hi,
I have a Word document containing a section and I want to insert the content of an other document which contains 2 sections.
I use the NodeImporter describes in the example of your How-to: Insert a document into another Document (insertDocument method)
I thought that if I call doc.UpdateFields() then all heading will be re numbered and the merged document will have the form:
1. Heading level 1 from Doc 1
2. Heading level 1 from Doc 2
2.1 Heading level 2 from Doc 2.
But it is not.
What can I do ?
In attachment there are the 2 files (File1.doc and File2.doc) and the output.docx (the result).
By the way, why the output.docx has 2 kinds of ‘Heading1’ style (‘Heading 1’ and ‘Heading 1_0’) ?
It is not possible to ‘merge’ the two styles ?
Thanks in advance.
Hi Roseline,
Thanks for your query. Aspose.Words layout engine mimics the same behave our as MS word do. The styles you are using has “Page Break Before” option set as true for Pagination. Please see the attached image.
Regarding your second question (‘Heading1’ style [‘Heading 1’ and ‘Heading 1_0’]), Please use the latest version of Aspose.Words for Java. I have not found this issue while using latest version of Aspose.Words for Java. Please find the output doc file in attachment.
Hope this answers you query. Please let us know if you have any more queries.
Hi Tahir,
Thanks for your answer.
I understand that if I have ‘Heading 1’ and ‘Heading 1_0’ it is because the styles are not merged and so the numbering are not keep (restart for each new style).
I have downloaded the last version of Aspose Java (11.4.0) but I still have the problem.
Have I done something wrong ? Shall I have to call some method ?
Here my code :
Document doc1 = new Document(new File(“D:\File1.doc”).getAbsolutePath()); DocumentBuilder builder = new DocumentBuilder(doc1);
Document wordDoc = new Document(new File(“D:\File2.doc”).getAbsolutePath()); insertDocument(builder.getCurrentParagraph().getNextSibling(), wordDoc);
doc1.updateFields();
doc1.save(“D:\output.docx”);
The insertDocument method is the same as found here: http://www.aspose.com/docs/display/wordsjava/How+to++Insert+a+Document+into+another+Document
And please find in attachment the two files and the output.docx (I have removed the ‘Page Break Before’).
Thanks in advance.
Hi Roseline,
Thanks for sharing the information. I have managed to reproduce the same problem at my end. I have logged this issue as WORDSJAVA-571 in our issue tracking system. You will be notified via this forum thread once this issue is resolved.
We apologize for your inconvenience.
Hi Roseline,
Further to my last post, the duplicate styles in output document (‘Heading 1’ and ‘Heading 1_0’) is not an issue.
The reason of these duplicate styles is, you have used the KeepSourceFormatting in the insertDocument method.
Using the KeepSourceFormatting option allows to make sure the imported text looks in the destination document exactly like it was in the source document. If a matching style already exists in the destination document, the source style is copied and given a unique name by
appending a suffix number to it, for example “Normal_0” or “Heading 1_5”.
When using the UseDestinationStyles option, if a matching style already exists in the destination document, the style is not copied and the imported nodes are updated to reference the existing style.
Please read following documentation link for your kind reference.
Thanks !
I had the same conclusion thanks to the topic <a href=" but still have the problem on my example. I will open a new topic for that.
Hi Roseline,
Please let us know if you have any more queries. We will be more than happy to help you.