We are seeing an issue where HTML containing two tables with same width settings renders incorrectly when imported into a Word Document. Although the tables contain identical width specifications for the columns in both tables - the columns become misaligned in the Word Document.
This behavior can be seen in the latest Aspose Cells for Java version 20.12, the attached
MisalignedTables.html file and the following Java code:
final String htmlSrc = [PATH] + "MisalignedTables.html"; // create a new Document and DocumentBuilder Document wdDoc = new Document(); DocumentBuilder builder = new DocumentBuilder(wdDoc); builder.moveToDocumentEnd(); // load and insert the SVG source into the doc String html = new String(Files.readAllBytes(Paths.get(htmlSrc)), "UTF-8"); builder.insertHtml(html, false); final String newDoc = htmlSrc.replace(".html", ".docx"); Files.deleteIfExists(Paths.get(newDoc)); wdDoc.save(newDoc); System.out.println("Saved Word Document: " + newDoc);
Running the above code should produce a new
MisalignedTables.docx file similar to the one attached.
- Opening the
MisalignedTables.htmlfile in a Browser (such as Firefox or Edge) - renders the two tables as expected, where the columns are perfectly aligned.
- Opening the generated DOCX in MS Word shows the two tables having the same widths (as expected), but the columns are misaligned. This becomes more obvious when the “show gridlines” options is turned on in MS Word.
- Aspose Cells for Java 20.12
- Java version 1.8.0_211
- Windows 10 OS (but also reproducible under Linux).
File description from the
MisalignedTables.zip (13.4 KB) attachment:
- MisalignedTables.html: Source HTML file used by the code above.
- MisalignedTables.docx: DOCX file generated by the code above on our environment.
- MisalignedTables.png: PNG screenshot of the HTML rendered in Firefox. This image represents the expected rendition in Word after the HTML is imported.