Object reference not set to an instance of an object (related to aw-style-name)

We are getting the error when converting a Word document to Html, and then converting the Html back to Word. After further investigation, we found the error was caused by this particular css:
span.UnresolvedMention { color:#605e5c; background-color:#e1dfdd; -aw-style-name:unresolved-mention }

Conversion from html to Word will start to work after removing “-aw-style-name:unresolved-mention”. What’s the reason this css is generated? What’s the best way to ignore this style name during conversion? Please advice. Thanks

1 Like

@khsiang

The error you’re encountering during the conversion from HTML back to Word is likely due to the presence of the -aw-style-name CSS property, which is not recognized during the conversion process. This property is typically generated by certain applications to manage styles but can cause issues when converting back to Word format.

To address this issue, you can preprocess the HTML to remove or modify any CSS rules that contain -aw-style-name. Here’s a simple approach using a regular expression in Java to remove such styles:

import java.util.regex.Pattern;

public class HtmlCleaner {
    public static String cleanHtml(String html) {
        // Regex to remove any style containing -aw-style-name
        String cleanedHtml = html.replaceAll("style=\"[^\"]*-aw-style-name:[^\"]*;?\"", "style=\"\"");
        return cleanedHtml;
    }
}

You can call the cleanHtml method before converting the HTML back to Word. This should help you avoid the error related to the unresolved style.

For further customization or specific requirements, please consult the Aspose.Words documentation for more options related to HTML and Word conversions.

This is a weird solution to just remove what Aspose.Words put during docx -> html conversion. I believe it’s a bug - Aspose.Words should be able to digest it’s own output back

1 Like

@khsiang @sgurenkov Could you please attach your problematic input document and code that will allow us to reproduce the problem? We will check the issue and provide you more information.