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

Free Support Forum - aspose.com

Heading style not working on doc.InsertHtml after upgrade

We recently upgraded from an older version to the current 15.10 for Aspose.Words, and it has broken the styling of headings. I attached a document showing the issue. The first insert DOES NOT display the correct H2 and H3 styling from the document, while the second and third does. Why is the first insert not displaying the correct styles as is displayed on the second two inserts?

var doc = new DocumentBuilder(new Document(input));
doc.MoveToMergeField("ProjectAgreementTerms");
doc.InsertHtml(@"

1 New Section

1.1 Title test

", true);

doc.MoveToMergeField("Milestones");
doc.InsertHtml(@"

Fixed Bid

", true);

doc.MoveToMergeField("UnitOfMeasures");
doc.InsertHtml(@"

Unit of Measure

", true);

doc.Document.Save(output, SaveFormat.Docx);
Hi Philip,

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-12686. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Philip,

Thanks for your patience. It is to inform you that our product team has completed the work on this issue (WORDSNET-12686) and has come to a conclusion that this issue and the undesired behavior you're observing is actually not a bug in Aspose.Words. So, we have closed this issue as 'Not a Bug'. We are quoting developer's comments here for your reference.

InsertHtml is instructed to merge target formatting with formatting specified in HTML fragments. However, formatting of the first merge field in the target document differs from formatting of other merge fields and, as a result, formatting of text inserted into the first merge field differs from formatting of text inserted to other merge fields.

Please remove direct font formatting of the first merge field to get the required output.

Document doc = new Document(MyDir + "headingsBroken.docx");

var builder = new DocumentBuilder(doc);

builder.MoveToMergeField("ProjectAgreementTerms");

builder.Font.ClearFormatting();

builder.InsertHtml(@"

1 New Section

1.1 Title test

", true);

builder.MoveToMergeField("Milestones");

builder.InsertHtml(@"

Fixed Bid

", true);

builder.MoveToMergeField("UnitOfMeasures");

builder.InsertHtml(@"

Unit of Measure

", true);

doc.Save(MyDir + "Out.docx", SaveFormat.Docx);