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

Free Support Forum - aspose.com

Inserting HTML with a DIV containing a Border is Ignored


We have HTML which contains a DIV node and a TABLE node nested within the DIV. The DIV has a thick border which wraps around the nested TABLE. When the HTML is rendered in a Browser, the border is shown. However, when the same HTML is added to a Word document, it seems to be ignored and the table appears without the border.

This behavior can be seen in the latest Aspose Words version 19.7, the attached div_table.html file and the following Java code:

final String htmlSrc = "div_table.html"; // prepend the *file path* if necessary
try {
    // create new blank document
    Document wdDoc = new Document();
    DocumentBuilder builder = new DocumentBuilder(wdDoc);

    // load the html
    final String html = new String(Files.readAllBytes(Paths.get(htmlSrc)));

    // add the paragraph to the document
    Paragraph para = new Paragraph(wdDoc);
    // add the new Paragraph to the end of the doc
    // insert the HTML into the doc - keep HTML formatting intact
    builder.insertHtml(html, false);

    // save the new Word doc
    final String newDoc = htmlSrc.replace(".html", ".docx");

    System.out.println("Saved Document:  " + newDoc);

} catch (Exception ex) {
    System.out.println("Unexpected EXCEPTION: \n\t" + ex.getMessage());

If you run the code above and compare the attached HTML file (rendered in a Browser) against the resulting DOCX file in Word, you should see the border defined in the DIV is missing in the Word document.

Note that removing the DIV and putting the border attribute in the TABLE node is not a feasible alternative - the border must be defined in the DIV.

Thank you !


Thanks for your inquiry. We tested the scenario and have managed to reproduce the same problem on our end. For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-19025. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.

A post was split to a new topic: Insert HTML with a DIV containing a Border in Word Document