Trying to insert an html table into a cell in a Word document and want fixed column widths as well as a fixed table width for the HTML table inserted. I do not seem to get the fixed column/table widths to work. The HTML code inserted is:
<table style=’text-align: center; width: 300px; border-left-style: solid; border-left-width: 1px; border-right: 1px solid #C0C0C0; border-top-style: solid; border-top-width: 1px; border-bottom: 1px solid #C0C0C0;’>
2
The table is inserted but not in the right size. I have tried without px and also with all widths as pixels. Now there is a catch here and I assume this is causing the problem: I have a bookmarked text that works as the HTML table template (will use this in several locations in my document). I read this and fill it with data, move to the bookmark I want to have the info and then I insert the HTML table. Could this be some kind of character conversion problem? Any ideas?
Hi
Thanks for your request. I tried to insert your HTML into a document and width of the table is correct. I use the latest version of Aspose.Words (6.2.0) for testing.
Could you please attach sample documents (input and output) for testing? I will investigate the issue and provide you more information.
Best regards.
Hi, here a sample document. I use the bookmark HA47160 and read the HTML template code from the HTMLTest bookmark
Hi
Thanks for your inquiry. The reason of the problem is the invalid quotes characters in your document. Here is snippet of HTML from the bookmark in your document:
<table style=’text-align: center; width: 300px; border-left-style: solid; border-left-width: 1px; border-right: 1px solid #C0C0C0; border-top-style: solid; border-top-width: 1px; border-bottom: 1px solid #C0C0C0;’>
<td style=’width: 20%;’>%1<td style=’width: 20%;’>%2<td style=’width: 20%;’>%3<td style=’width: 20%;’>%4<td style=’width: 20%;’>%5
I highlighted characters that cause the problem. These characters are 8217 char, but should be 39. You can try using the following code to resolve the issue, or just correct your document.
Document doc = new Document(@"Test026\QAQuestionnaireFormTemplateCustom0.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
string html = doc.Range.Bookmarks["HTMLTest"].Text.Replace("’", "'");
builder.MoveToBookmark("HA47160");
builder.InsertHtml(html);
doc.Save(@"Test026\out.doc");
Best regards, Alexey.
Right! Word automatically replaces… Thanks for your very fast answer, ask for more salary!