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

Free Support Forum - aspose.com

Override style doesn't work

Hi !

We have an issue about style overriding.
How to reproduce :

  • Create a brand new word document
  • Type something
  • Set Heading-2 style for the text
  • Modify Heading-2 style and disable italic formatting
  • Create a new com.aspose.words.Document with the file
  • Convert this doc to HTML
  • Convert the HTML to a new Document
  • Write the Document on the filesystem
    => The text is in italic in the exported word doc.

Here is the snippet I use :

	public static void main(final String[] args) throws Exception {
	final LoadOptions lo = new LoadOptions();

	// READ
	final String s;
	final Document doc = new Document(FOLDER + "testHeader2.doc", lo);
	try (final NoBomByteArrayOutputStream bos = new NoBomByteArrayOutputStream()) {
		doc.save(bos, getSaveOptions(doc));
		s = bos.toUtf8String();

	final byte[] bytes;
	final Document document = new Document();
	final DocumentBuilder builder = new DocumentBuilder(document);
	builder.insertHtml(s, true);
	try (final ByteArrayOutputStream output = new ByteArrayOutputStream()) {
		final OoxmlSaveOptions so = new OoxmlSaveOptions(SaveFormat.DOCX);
		document.save(output, so);
		bytes = output.toByteArray();
	try (final ByteArrayInputStream input = new ByteArrayInputStream(bytes)) {
		new Document(input, lo).save(FOLDER + "testHeader2Exported.doc");

We use local.aspose.words v18.6.

Do you know what’s happening ?


Thanks for your inquiry.

In MS Word’s default template, the “Heading 4” has italic formatting at our end. We have modified this style to test this issue using the latest version of Aspose.Words for Java 18.11. We have not found the shared issue. So, please use the latest version of Aspose.Words.

We updated our lib version to v18.11. It doesn’t change anything to the issue (see screenshot). I can’t find “Heading 4” in my word version but if I use “Heading 2” it’s still not working.
The license isn’t correctly set for my main but we do use it right in production. Could you advise us about this issue ?

image.png (43.1 KB)


Thanks for your inquiry.

Please create this document, ZIP and attach it here for testing. Please also share the problematic output document. We will investigate the issue and provide you more information on it.

Here is the requested zip :

asposeArchive.zip (36.7 KB)


Thanks for sharing the detail. You are facing the expected behavior of Aspose.Words. In your code, you are inserting the HTML into document using DocumentBuilder.InsertHtml (html, true) method.

When second parameter of this method is true , formatting of inserted text is based on DocumentBuilder formatting, and the text looks as if it were inserted with Write.

Please use false value of second parameter of DocumentBuilder.InsertHtml method to get the desired output.

final Document document = new Document();
final DocumentBuilder builder = new DocumentBuilder(document);
builder.insertHtml(bos.toString(), false);


It’s working well with the false boolean. We didn’t understand well enough the API.
Thanks a lot for your time.

Have a nice day !


Thanks for your feedback. You are inserting the HTML into empty document (new Document()). It has style ‘Heading 2’ with italic font formatting. You can check it with following line of code.


When the second parameter of InsertHtml method is true, font formatting is used based on DocumentBuilder formatting. In this case, H2 tag is imported as ‘Heading 2’ style that has italic formatting. Please check the detail of DocumentBuilder.InsertHtml method.