Issue while inserting html table at a bookmark

Hi ,

I am using Aspose.words for java 3.2.0. I am trying to insert HTML table at a bookmark position. I am trying to set width and align = "center" to <td>. I got different results when I use style attribute of <td> and with width and align attributes of <td>.

I have tested with the below code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

String html = " <h1> First Table </h1> "
        + " <table border=1 width=\"500px\">"
        +     " <tr>"
        +         " <td align=\"center\" width=\"250px\"><strong>First Column</strong></td> "
        +         " <td width=\"250px\"><strong>Second Column</strong></td> "
        +     " </tr>"
        + " </table>"
        + " <h1> Second Table </h1> "
        + " <table border=1 width=\"500px\"> "
        +     " <tr>"
        +         " <td align=\"center\" style=\"width:250px;\"><strong>First Column</strong></td> "
        +         " <td style=\"width:250px;\"><strong>Second Column</strong></td> "
        +     " </tr>"
        + " </table> "
        + " <h1> Third Table </h1> "
        + " <table border=1 width=\"500px\"> "
        +     " <tr>"
        +         " <td width=\"250px\" style=\"text-align:center;\"><strong>First Column</strong></td> "
        +         " <td width=\"250px\"><strong>Second Column</strong></td> "
        +     " </tr>"
        + " </table> "
        + " <h1> Fourth Table </h1> "
        + " <table border=1 width=\"500px\"> "
        +     " <tr>"
        +         " <td style=\"width:250px; text-align:center;\"><strong>First Column</strong></td> "
        +         " <td style=\"width:250px;\"><strong>Second Column</strong></td> "
        +     " </tr>"
        + " </table> ";

builder.insertHtml(html);

doc.save("C:\\Temp\\out.doc", SaveFormat.DOC);

Attached the out.doc for your reference.

Hi

Thanks for your inquiry. I see only two problems here.

  1. In your HTML you specified width via TD attribute improperly. Due to HTML specification width attribute may be either a %Pixel; or a percentage of the available horizontal or vertical space. So you cannot specify measurement units in width attribute. Your HTML should look like the following:
String html = " <h1> First Table </h1> "
    + " <table border=1 width = \"500\"> <br>"
    +     " <tr> <br>"
    +         " <td align=\"center\" width=\"250\"><strong>First Column</strong></td> <br>"
    +         " <td width=\"250\"><strong>Second Column</strong></td> <br>"
    +     " </tr><br>"
    + " </table> <br> <br> <br>"
  1. Problem with alignment, when you specify it using style attributes. This occurs because currently, Aspose.Words does not support inheriting styles from parent elements. I linked your request to the appropriate issue. You will be notified as soon as it is resolved.

Best regards,

The issues you have found earlier (filed as WORDSNET-2021) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(45)