Hello,
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
wdDoc.getLastSection().getBody().appendChild(para);
builder.moveTo(para);
// 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");
Files.deleteIfExists(Paths.get(newDoc));
wdDoc.save(newDoc);
System.out.println("Saved Document: " + newDoc);
} catch (Exception ex) {
System.out.println("Unexpected EXCEPTION: \n\t" + ex.getMessage());
ex.printStackTrace();
}
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 !