We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Append Word Documents to other DOCX - Preserve List Style Font Color Layout using .NET C# API

Hi,

We have a requirement where in we have to merge n number of docx files, with varied formatting and styling, in to a single docx file.
For this purpose I am evaluating latest Aspose.Words.
Following is the code I used to merge all docs in to one but the generated file is not preserving the source styles.

ImportFormatOptions importFormatOptions = new ImportFormatOptions();
importFormatOptions.SmartStyleBehavior = true;
importFormatOptions.KeepSourceNumbering = true;

        Document doc = new Document(sourcefiles[0]);           

        for (int i = 1; i < sourcefiles.Length; i++)
        {
            Document doc1 = new Document(sourcefiles[i]);
            doc1.ExpandTableStylesToDirectFormatting();
            doc1.FirstSection.HeadersFooters.LinkToPrevious(false);
            doc.AppendDocument(doc1, ImportFormatMode.KeepSourceFormatting, importFormatOptions);                
        }

        doc.Save(destfile,SaveFormat.Docx);

For security reasons, I can’t send you my source files.
Following are the differences I could see:

  1. Some paragraph styles are not applied: Source contains a bullet list whose style is set to ‘List Paragraph’ and in the merged document it is bullet list with out the style
  2. Font issues: For some sources font is specified as Calibri (Body) in source and it is set to Calibri in destination or vice versa.
  3. Font color is getting changed for some docs.
  4. Extra line (empty line) is inserted after few headings.

Is there any way to merge multiple documents with different styles, margins, headers and footers be merged in to one with out disturbing any of the styles?

Thanks,
Anupama

@mattaanupama,

We have now marked your thread as ‘private’. It is safe to attach files in the forum. If you attach your documents/resources here, only you and Aspose staff members can view/download them. You can also remove any sensitive information from documents by replacing it with dummy data instead.

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word documents
  • Aspose.Words for .NET 19.11 generated output DOCX file showing the undesired behavior
  • Your expected DOCX file showing the desired output. You can create this document by using MS Word.
  • Please also create a standalone simple Console application (source code without compilation errors) that helps us to reproduce your current problems on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your scenario and provide you more information. Thanks for your cooperation.

Hi Awais.hafeez,

I have attached the samples, output generated by Aspose (OutputByAspose.docx) and the expected output (Expected - Result.docx) and the source code (AsposeMergeDoc.cs).

You could see the differences like:
List formatting not preserved - Page 21 in the result which is Page 19 in expected doc.etc.,
Extra new lines added in pages - 42, 47, 48, 49 etc.,
Table formatting disturbed - page No 53 etc.,
Top/Bottom margin/header changes - Page 23, 30 etc.,

Also in few pages font changes like - from Calibri (body) to Calibri, Calibri (Heading) to Calibri etc.,

Thanks,
Anupama

Thanks,
Anupama

TestSamples.zip (3.6 MB)

@mattaanupama,

We are working on your query and will get back to you soon.

Hi Awais.hafeez,

Any update here?
Could you please let us know the status here as my test license is about to expire.

Thanks,
Anupama

@Anupama123,

Thanks for being patient. Please spare us some time for this issue, we will get back to you with our findings today.

@Anupama123,

We tested the above scenarios and have managed to reproduce the same problems on our end. For the sake of corrections, we have logged the following issues in our issue tracking system.

WORDSNET-19756: Some list paragraph styles not preserved during appending documents
WORDSNET-19757: Calibri (Body) changes to Calibri or vice versa during appending documents
WORDSNET-19758: Extra new lines appear in pages during appending documents
WORDSNET-19759: Table formatting disturbed during appending documents
WORDSNET-19760: Top/Bottom margin/header changes during appending documents

We will further look into the details of these issues and will keep you updated on the status of corrections. We apologize for your inconvenience.

Please also provide a comparison screenshot highlighting the problematic areas in the Aspose.Words generated output file with respect to your original document (also specify the source file name) and attach it here for our reference. We will then investigate the issue further on our end and provide you more information. Thanks for your cooperation.

Hi awais.hafeez,

Thanks for confirming that the issues are re-producible on your end.
Is there any ETA for the fixes?
As I am evaluating different tools for my project requirement, it is great if you could provide an ETA for the fixes which helps us to decide.

Thanks,
Anupama

@Anupama123,

I am afraid, your issues are currently pending for analysis and are in the queue. There are no estimates available at the moment. Once the analysis of these issues will be completed, we may then be able to calculate and share the ETAs of these issues with you. We apologize for your inconvenience.

@Anupama123,

Regarding WORDSNET-19756, we have completed the work on your issue and most likely will close this issue with “Not a Bug” status. Please check below the analysis details:

Aspose.Words mimics/relies on MS Word’s behavior and in this case MS Word’s behavior is the same as that of Aspose.Words.

We have made simplified documents (destination.docx and source.docx) to illustrate this. To make sure, please, set the “Keep Source Formatting” option in MS Word (see screenshot)

Then open destination.docx and source.docx, copy the source document to the destination by using MS Word. The problematic paragraph will have the “Normal” style. (same as in Aspose.Words’ output).

If you want to receive the “List Paragraph” style for this paragraph, please use the ImportFormatMode.UseDestinationStyles instead of ImportFormatMode.KeepSourceFormatting.

Hope, this helps.

@mattaanupama, @Anupama123,

Can you please also tell us about the source of your expected document and what application did you use to create your expected Word document e.g. MS Word or OpenOffice Writer or some other? Also, please tell the exact version number of that application. Thanks for your cooperation.

Hi awais.hafeez,

Source of expected document is Word itself but with few adjustments after importing/merging the docs.
I have also tried the same with Syncfusion’s docio and it is actually producing the merged doc as expected.

Thanks,
Anupama

@mattaanupama,

Thanks for sharing this information.

Can you please also share the steps that we can follow to reproduce the same expected document on our end?

Also, we have created a new output document (see 20.2.zip (831.8 KB)) using the latest version of Aspose.Words for .NET i.e. 20.2 on our end, do you still see the same above problem in this document? If yes, can you please create and attach here a comparison screenshot (with respect to the expected document you attached earlier) highlighting the problematic areas on page 23 and 30?

Thanks for your cooperation.

@mattaanupama,

Regarding above issue, please also confirm that the document before adjustments was the same as Word’s output?

The issues you have found earlier (filed as WORDSNET-19757) have been fixed in this Aspose.Words for .NET 20.4 update and this Aspose.Words for Java 20.4 update.