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

Free Support Forum - aspose.com

InsertHtml problem with tables and images

i have two problems with insertHtml :

  1. i am inserting a table through insertHtml, i want to show background color in table,but it is not showing the
    background color.i am using this code for inserting table through
    insertHtml:











    cell1 cell2
    cell3 cell4
  2. i am inserting an image through insertHtml,how i can make it center align(means which tag should i use for this)

thanks in advance



Hi Vuong,

Thank you for contacting support.

1) Normally, to change the background color of the table, the attribute bgcolor is used. I have slightly modified your input HTML string; please see the following code snippet that worked for me:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

StringBuilder sb = new StringBuilder();
sb.Append("<table cellspacing='0' border='1' bgcolor='#FFDD00' style='border: 1px solid rgb(0, 0, 0); border-collapse: collapse;'>");
sb.Append("");
sb.Append("");
sb.Append("cell1");
sb.Append("cell2");
sb.Append("
"
);
sb.Append("");
sb.Append("cell3");
sb.Append("cell4");
sb.Append("
"
);
sb.Append("
"
);
sb.Append("");

string html = sb.ToString();

builder.InsertHtml(html);
doc.Save("C:\\test.docx");

2) To make image centre aligned, you could wrap it inside a DIV tag and to make it middle aligned use align attribute e.g. align="absmiddle" or align="middle". Please see the following code snippet:

<div style="text-align: center;">
<img width="550" height="825" src="58.jpg" align="middle" />This tells that image is centerlized
</div>

I hope, it will help

Best Regards,