Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 10, 2020 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/0e5aba636419098aef07e054cbd08d77 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0e5aba636419098aef07e054cbd08d77 to your computer and use it in GitHub Desktop.
// Load Word documents to be merged
Document doc1 = new Document("sample1.docx");
Document doc2 = new Document("sample4.docx");
// Set options
ImportFormatOptions options = new ImportFormatOptions();
options.setIgnoreHeaderFooter(true);
//options.setIgnoreTextBoxes(true);
//options.setKeepSourceNumbering(true);
//options.setSmartStyleBehavior(true);
// Merge documents keeping destination file's styles
doc1.appendDocument(doc2, ImportFormatMode.USE_DESTINATION_STYLES, options);
// Save merged document as DOCX file
doc1.save("merged-customized.docx", SaveFormat.DOCX);
// Load Word documents to be merged
Document doc1 = new Document("sample1.docx");
Document doc2 = new Document("sample4.docx");
// Merge documents keeping source file's formatting
doc1.appendDocument(doc2, ImportFormatMode.KEEP_SOURCE_FORMATTING);
// Save merged document as DOCX file
doc1.save("merged.docx", SaveFormat.DOCX);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment