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

Free Support Forum - aspose.com

Merging Document Issue "There are too many styles in the document"

Hi Aspose team,
In .NET, I have trouble with style merging “There are too many styles in the document” when I try to insert content from a document to a target document.
I attached target document and content document into this topic
Documents.zip (266.4 KB)
Here is my example code:

public static void InsertContent(Document targetDocument, Document contentDocument)
{
    List<Section> allSectionsOfContent = contentDocument.Sections.Cast<Section>().ToList();

    foreach (Section sectionOfContent in allSectionsOfContent)
    {
        targetDocument.RemoveUnusedResources();

        var importedSection = (Section)targetDocument.ImportNode(sectionOfContent, true, ImportFormatMode.UseDestinationStyles);
    }
}

Do you have any clue for my problem ?
Thank in advance
Best regards

@peter.peterson

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-17605. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thanks for your support. Hope this issue will be solved soon.

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

The issue isn’t resolved, You can try with my sample code.

@peter.peterson

Thanks for your inquiry. Please make sure that you are using the latest version of Aspose.Words for .NET 18.11. Please use the following code to get the desired output.

public static void InsertContent(Document targetDocument, Document contentDocument)
{
    CleanupOptions cleanupOptions = new CleanupOptions();
    cleanupOptions.UnusedLists = true;
    cleanupOptions.UnusedStyles = true;

    contentDocument.Cleanup(cleanupOptions);

    List<Section> allSectionsOfContent = contentDocument.Sections.Cast<Section>().ToList();

    foreach (Section sectionOfContent in allSectionsOfContent)
    {
        targetDocument.Cleanup(cleanupOptions);

        var importedSection = (Section)targetDocument.ImportNode(sectionOfContent, true, ImportFormatMode.UseDestinationStyles);
    }
}

InsertContent(new Document(MyDir + "TargetDocument.docx"), new Document(MyDir + "ContentDocument.docx"));

Thank you so much Tahir :slight_smile:

Hi Tahir, I have other issue after applying your solution. Could you please have a look on this Documents2.zip (74.4 KB)
:
In target document, I created 4 styles “1Style1”, “2Style1”, “3Style1” and “4Style1” in Target.doc.
After I’d inserted content of Content.doc into Target.doc, the style “4Style1” is missing.

Do you help any clue for this ?
Thank in advance
Best regards

@peter.peterson

Please use the latest version of Aspose.Words for .NET 19.7 and do not use CleanupOptions if you want to keep desired styles in the output document.

Hi @tahir.manzoor,
But without CleanupOptions, the “Too many styles” issue will come again

@peter.peterson

Please try the latest version of Aspose.Words for .NET 19.7. Hope this helps you.

Hi @tahir.manzoor , I tried the latest Aspose 19.7, but without CleanupOption, the “Too many styles” issue still occurs.
I posted another issue. Could you please a have look on that ?
Thank in advance

@peter.peterson

We have answered your query in your other thread. Please follow that thread for further proceedings.

Thank you for your support @tahir.manzoor. And how’s about the CleanupOption and style missing issue above ? Do you have any clue for it :slight_smile:

@peter.peterson

We have tested the scenario using the latest version of Aspose.Words for .NET 19.8 with the code example shared in this thread. We have not found the shared issue. So, please use Aspose.Words for .NET 19.8.

If you are using different code, please share it here for further testing. We will investigate the issue and provide you more information on it.

I checked, it worked without CleanupOption.
Thank you so much @tahir.manzoor