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

Free Support Forum - aspose.com

InvalidOperationExecution : There are too many styles in the document

Hello,

I see error while I try to insert a Horizontal Line in the Words.Document object. I have same cod running in 650 times in a loop. It works file until it reaches certain no and gives error " InvalidOperationExecution : There are too many styles in the document."

I am not sure why it works fine for some part of loop and blows up later around 600+ times iteration.

I am just trying to append a line in the document object.

Dim lobjLineDoc As New Aspose.Words.Document

Dim lobjDocBuilder As Aspose.Words.DocumentBuilder = New DocumentBuilder(lobjLineDoc)

Dim lWidth As Double = lobjDocBuilder.CurrentSection.PageSetup.PageWidth

Dim lLine As New Aspose.Words.Drawing.Shape(lobjLineDoc, Drawing.ShapeType.Line)

lLine.Width = lWidth / 2

' '' ''lLine.RelativeHorizontalPosition = Drawing.RelativeHorizontalPosition.Page

lLine.HorizontalAlignment = Drawing.HorizontalAlignment.Center

lLine.RelativeVerticalPosition = Drawing.RelativeVerticalPosition.Paragraph

lLine.StrokeColor = Color.Black

lLine.Stroke.LineStyle = Drawing.ShapeLineStyle.Single

lLine.StrokeWeight = 1

lobjDocBuilder.CurrentSection.PageSetup.SectionStart = SectionStart.Continuous

lobjDocBuilder.InsertNode(lLine)

lobjLineDoc.FirstSection.PageSetup.SectionStart = SectionStart.Continuous

lobjLineDoc.FirstSection.PageSetup.PaperSize = Aspose.Words.PaperSize.Legal

mobjMainAsposeDoc.AppendDocument(lobjLineDoc, ImportFormatMode.KeepSourceFormatting)

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. This occurs because when you use ImportFormatMode.KeepSourceFormatting, all styles from the source document will be copied into the destination document. That’s why when you run this code in the loop number of styles in the document overflows a maximum value. The solution is quite simple. Just use ImportFormatMode.UseDestinationStyles.

mobjMainAsposeDoc.AppendDocument(lobjLineDoc, ImportFormatMode.UseDestinationStyles)

Hope this helps.

Best regards.