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

Free Support Forum - aspose.com

Formatting corrupt and styles lost after using AppendDocument

We are using the latest build of Aspose.Words downloaded just last week. We have very simple code below that combines 2 documents together from memory and are performing this 3 times to create a single document from 4 seperate DOCX files. The output is nothing like the output we get when using MS Word automation, which correctly appends each document with page breaks and does not insert extra spacing or overwrite default styles for each document, rather merges and renames or embeds them appropriately.
With Aspose.Words, it appears after appending these 4 documents we get an unexpected outcome (see attached). The GUID file name, “26fa68c4336644fb8dec41737919f762.docx” is the final output of appending the 4 documents.
Thanks,
Chad

public static MemoryStream CombineDocuments(MemoryStream msDstDoc, MemoryStream msSrcDoc)
{
    msDstDoc.Position = 0;
    AW.Document dstDoc = new AW.Document((Stream)msDstDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);
    msSrcDoc.Position = 0;
    AW.Document srcDoc = new AW.Document((Stream)msSrcDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);
    dstDoc.AppendDocument(srcDoc, Aspose.Words.ImportFormatMode.KeepSourceFormatting);
    MemoryStream ms = new MemoryStream();
    dstDoc.Save((Stream)ms, Aspose.Words.SaveFormat.Docx);
    return ms;
}

Hi
Thanks for your request and sorry for delayed response. I managed to reproduce the problem and created new issue #7603 in our defect database.
The problem occurs because “No Spacing” style from “Cigna_CHCP - Employee.docx” is copied to destinations document not properly for some reason. As a workaround you can try using the following code:

public MemoryStream CombineDocuments(MemoryStream msDstDoc, MemoryStream msSrcDoc)
{
    msDstDoc.Position = 0;
    Document dstDoc = new Document((Stream)msDstDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);
    msSrcDoc.Position = 0;
    Document srcDoc = new Document((Stream)msSrcDoc, string.Empty, Aspose.Words.LoadFormat.Docx, string.Empty);
    dstDoc.AppendDocument(srcDoc, Aspose.Words.ImportFormatMode.UseDestinationStyles);
    MemoryStream ms = new MemoryStream();
    dstDoc.Save((Stream)ms, Aspose.Words.SaveFormat.Docx);
    return ms;
}

However this will not fully solve the problem, because first (Eligibility_EE.docx) and second (Cigna_CHCP - Employee.docx) documents contains style “No Spacing”. However, formatting defined in this style is different in first and second document. In the first document font size is 11, and in the second 10.
Best regards.

The issues you have found earlier (filed as WORDSNET-2098) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(5)