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

Free Support Forum - aspose.com

Inserting a text to a paragraph does not retain its style anymore in version 13.11.0


Please see the attached Word document: it has one paragraph with a bookmark in it. In the code snapshot below, I use this document and insert some text before the bookmark. When using Aspose.Words 13.9.0 (and all releases before), the style of the paragraph remains unchanged after the text is inserted. In version 13.11.0, the paragraph style changes to Normal.

Code example:

Document doc = new Document("c:/insertTextRetainStyle.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

<span style=“font-size:
10.0pt;font-family:“Courier New””>builder.moveToBookmark( “bookmark”,
true, false );

<span style=“font-size:
10.0pt;font-family:“Courier New””>builder.insertHtml("Some text before

<span style=“font-size:
10.0pt;font-family:“Courier New””><span style=“font-size:
10.0pt;font-family:“Courier New””>OoxmlSaveOptions saveOptions = new
OoxmlSaveOptions( SaveFormat.DOCX ); saveOptions.setCompliance(
OoxmlCompliance.ISO_29500_2008_TRANSITIONAL );

<span style=“font-size:
10.0pt;font-family:“Courier New””>doc.save(“c:/output.docx”,

<span style=“font-size:10.0pt;line-height:115%;font-family:“Tahoma”,“sans-serif”;

Please let me know if this can be fixed.


<!–[if gte mso 9]>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin;}


Hi Natasa,

Thanks for your inquiry.

While using the latest version of Aspose.Words i.e. 13.11.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The Id of this issue is WORDSNET-9421. Your request has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best regards,

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

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


This issue has not been resolved to match the behavior from release 13.2.0 or earlier. Neither this resolution matches the behavior I get when I manually insert a portion of a paragraph into an existing paragraph in Word. In both these cases, inserted text automatically accepts the styling and formatting of the original paragraph.

However, in 14.8.0 release, the inserted text is formatted as Normal (Web) style (or something else, as the Normal (Web) is paragraph based and it should not be allowed to be assigned to paragraph portions), while the remainder of the paragraph has its original formatting/styling.

Please see the attached document: output-14.8.0.docx - that’s the output I am getting when running the code snippet from the post above. If you click at any portion of inserted text and try to get its style, you may notice that it points to Heading 2 style, which is the style of the original paragraph. This is not OK behavior either.

Please let me know if this issue can be reopened and fixed. Also, please let me know if you have any questions or need any additional information.



Hi Natasa,

Thanks for your inquiry. In version Aspose.Words (14.6.0), we have introduced a new overload of DocumentBuilder.InsertHtml method which allows you to choose what formatting will be used as a base for inserted HTML fragments.

The new overload has an argument useBuilderFormatting which when is false, formatting specified in DocumentBuilder is ignored, and formatting of inserted text is based on default HTML formatting. In this case, inserted text looks as in browsers.

When useBuilderFormatting is true, formatting of inserted text is based on formatting specified in DocumentBuilder. Note that useBuilderFormatting chooses only base formatting of inserted text, and do not affect formatting directly specified in the HTML fragment.

The following example illustrates the difference between the two modes:

DocumentBuilder builder = new DocumentBuilder();

builder.ParagraphFormat.LeftIndent = 72;

builder.Font.Name = "Arial";

builder.Font.Size = 24;

bool useBuilderFormatting = ...



, useBuilderFormatting);

In this example, if useBuilderFormatting is false, the inserted paragraph will have no left indent and will use the 'Times New Roman' 12pt font, which is the default HTML font and indent. If useBuilderFormatting is true, the inserted paragraph will be indented by 1 inch (72 points) and will use the 'Arial' 24pt font, as specified in DocumentBuilder. However, in both cases the inserted text will be bold and red, as specified in the HTML fragment.

So, please try using this method as follows:

builder.InsertHtml("Some text before ", true);

Best regards,

Hi Awais,

Thank you very much for your response. I have tried this out and now it works as we need it to.
I appreciate your help.


Hi Natasa,

Thanks for your feedback. It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,