Aspose.Words - There are too many styles in the document

Wen using Aspose.Words for large documents, we get the error “There are too many styles in the document” and the document is not generated.
Please can you advise how to get around this problem?
If there is no work around at this time, can you advise us of the Style limit for word? Posts on your forum indicate that for Excel the limit is around 500 styles.
Kind Regards

1 Like

Hi
Thanks for your inquiry. You can try using a few documents instead one big document. I will consult with our developers and provide you more information about this problem soon.
Best regards.

Hi
MS Word limit is 4096 styles. Please let me know if you would like to know something else.
Best regards.

Hi,

wo concatenate several documents (up to >5000) with Aspose.words for java. So we often rach the liit of 4096 styles.

We cant use UseTargetFormattings because we have to keep the source formattings.

Is there any solution?

Our workaround is to split the large document in few smaller ones. But our customizers want one big document.
the exception we get is:

[WARNING]: There are too many styles in the document.
java.lang.IllegalStateException: There are too many styles in the document.
at com.aspose.words.StyleCollection.SM(StyleCollection.java:163)
at com.aspose.words.StyleCollection.a(StyleCollection.java:574)
at com.aspose.words.NodeImporter.a(NodeImporter.java:226)
at com.aspose.words.NodeImporter.importNode(NodeImporter.java:146)
at com.aspose.words.NodeImporter.a(NodeImporter.java:216)
at com.aspose.words.NodeImporter.importNode(NodeImporter.java:138)
at com.aspose.words.NodeImporter.a(NodeImporter.java:216)
at com.aspose.words.NodeImporter.importNode(NodeImporter.java:138)
at com.aspose.words.NodeImporter.a(NodeImporter.java:216)
at com.aspose.words.Document.appendDocument(Document.java:809)

Thanks a lot!
Kind regards,

Jens Böckel
ABACUS Research AG
Switzerland

Hi Jens,
Thanks for your request. Unfortunately, I cannot suggest you any other workarounds than reducing number of styles in the document by using UnseDestinationStyles option upon concatenating documents and reducing size of the final document (as you are doing now).
As I already mentioned this is not restriction of Aspose.Words, this is restriction of MS Word formats.
Best regards,

Hi Jens,
Do the documents you join together contain many identical styles? (styles in the destination and source document which have the exact same formatting). Appending these documents with KeepSourceFormatting will still create a copy of the source document’s style in the destination document even though they are identical.
If this is the case you may perhaps benefit from a new import mode which does not copy identical styles when the same style already exists in the destination document. We can link your request to the appropriate issue if this is what you are looking for.
Thanks,

Hi Adam ,

thank you very much for your reply. Yes the source documents are based on the same template, so the styles should be equal.
So a new import mode would be great!

Thanks again!

Kind regards,

Jens Boeckel
----------------------
Software-Engineer
Abacus Research AG
Switzerland

Hi Jens,
Thanks for your inquiry.
I have logged your request in our system. We will keep you informed of any developments.
In the mean time you can try using the class below to achieve the same effect. I wrote this code a while ago and have just converted it to Java. It should let you append multiple documents while keeping source formatting and avoiding nearly all redundant additional styles.
You can use the code as demonstrated below, by passing the destination document into the contructor of the class and then calling the AppendDocument method for each source document to append.

Document srcDoc1 = new Document("SrcDocument1.docx");
Document srcDoc2 = new Document("SrcDocument2.docx");
Document dstDoc = new Document("DstDocument.docx");

ImportDocumentDifferentStylesOnly nodeImporter = new ImportDocumentDifferentStylesOnly(dstDoc);
nodeImporter.AppendDocument(srcDoc1);
nodeImporter.AppendDocument(srcDoc2);
dstDoc.save("Document Out.docx");

Thanks,

Dear Adam,

thank you very much for your suggestion. Unfortunately the class ImportDocumentDifferentStylesOnly does not exists in our aspose.words java library.

Do you have any news about the request?

Thank you very much!
Kind regards

Jens Boeckel
----------------
Abacus Research AG
Switzerland

Hi Jens,
Thanks for your inquiry. ImportDocumentDifferentStylesOnly is not a part of Aspose.Words. It is a custom class created by Adam. You can find it in the attachment of the last Adam’s post.
Best regards,

Hi Alexey,

thank you very much. I tested the file. It looks nice.

I hope it will be integrated a little optimized (List instead of ArrayList, lowercases methods…) into the next java version of aspose.words.

Kind regards

Jens Böckel
---------------------------
Abacus Research AG
www.abacus.ch
Switzerland

Hello
It is perfect that you already resolve the problem. We will keep you informed on any developments regarding this issue.
Best regards,

Dear Adam,

we’ve got the same problem right now…
Can you provide a C#-Version of your class? That would be great!

Kind regards,
Bernd

Hi Bernd,
Thanks for your inquiry.
Sure, please find the class attached to this post. If you have any troubles, please feel free to ask.
Thanks,

Hi Adam.
Where can I find the interface NodeChangedEventHandler’?, I have just start using the product (words for java) and ran into this problem with too many styles, and I found this post.
I would like to implement this fix, I’ve downloaded the latest version of words for java.
Also I had to chnage other things like getBaseStyle() to getBaseStyleName() etc.
is this for an older version?
private
class ImportDifferentStylesHandler implements NodeChangedEventHandler
Thanks for your help,
Eamonn

Hello
Thanks for your inquiry. NodeChangedEventHandler was replaced with INodeChangingCallback:
https://reference.aspose.com/words/net/aspose.words/inodechangingcallback/
Hope this helps.
Best regards,

Hi,
Do you have a new copy of the class ‘ImportDocumentDifferentStylesOnly’ that I can use? (I took the attcahment from the original post)
mDstDoc.addNodeChangedEventHandler(handler) method is no longer available?
Thanks,
Eamonn

Hi there,

Thanks for your inquiry.

First before using this class we should make sure that this work around is required. Could you explain how you are running into this error? Perhaps if it’s suitable for you, you could try importing nodes using destination styles instead? This would avoid this issue altogether. Please see this article here for details on the different import modes: https://docs.aspose.com/words/net/insert-and-append-documents/

If it’s found you really need this work around then I will be happy to port it to an older version of the API for you. It should’t take many changes.

Thanks,

Hi
Thanks for your request. I modified the class for you. Please see the attachment.
Best regards,

Much appreciated