ImportFormatOptions

Hello,

I need help understanding the impact of setting a specific parameter on two merged Word documents with numbering.

When I run the following code, the output document remains unchanged whether I set KeepSourceNumbering to true or false. My expectation is that setting KeepSourceNumbering to false would result in the destination document pages being numbered sequentially (1, 2, 3, 4, …, 12), followed by the source document pages restarting at 1 (1, 2, 3, 4). Instead, the pages are numbered continuously (1, 2, 3, 4, …, 12, 13, 14, 15).

What is the code setting supposed to do?

Document srcDoc = new Document("\\srcDoc.docx");
Document dstDoc = new Document("\\destDoc.docx");
// Specify that if numbering clashes in source and destination documents,
// then numbering from the source document will be used.
ImportFormatOptions options = new ImportFormatOptions { KeepSourceNumbering = false};
dstDoc.AppendDocument(srcDoc, ImportFormatMode.UseDestinationStyles, options);

// Save the final document.
string outputFilePath = "JoinAndAppendDocuments.InsertDocument.docx";
dstDoc.Save(outputFilePath);

I have included my input and output test documents so that you can see what I mean.

Kind regards,
djs
Aspose Support Issue.zip (71.8 KB)

@djsomers1000 KeepSourceNumbering requires to lists in the different documents. If we set the “KeepSourceNumbering” flag to “false”, then the list from the document clone that we append to the original will carry on the numbering of the list we append it to. This will effectively merge the two lists into one. If we set the “KeepSourceNumbering” flag to “true”, then the document clone list will preserve its original numbering, making the two lists appear as separate lists.

Your document has a PageNumber field that always displays the current page number. To get the desired result, you need to use the following code after adding a document:

dstDoc.Sections[1].PageSetup.RestartPageNumbering = true;

Hi,

Thanks for getting back to me.

A senior developer and I have been trying to understand the impact of the ImportFormatOptions class on inserted and appended documents. Despite setting various properties within this class while creating test documents, we haven’t observed any changes in the outputted document.

The only exception is the AdjustSentenceAndWordSpacing property, which shows a visible effect on the output DOCX file.

These are the properties that we are setting:
ImportFormatOptions Class | Aspose.Words for .NET

Could you provide some sample documents to verify that the save options are working correctly? We’re unable to see any differences in our tests.

Kind regards,
djs

@djsomers1000 Please check our GitHub examples for those properties:

Thanks, I will take a look ASAP.