Free Support Forum - aspose.com

Table border is changed after inserting HTML into document using C#

Hi,

I have set table border to “1” and using Inserthtml method .

Everything is displayed but table and cell border is missing.

I have given code like below

Aspose.Words.Document doc = new Aspose.Words.Document();

        DocumentBuilder builder = new DocumentBuilder(doc);

        // Insert the table from HTML. Note that AutoFitSettings does not apply to tables
        // Inserted from HTML.
        builder.InsertHtml("<h1><a name=_Toc424545941>Assessment Plan Details</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Assessment Name</p></td><td><p>Enable User</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Assessment ID</p></td><td><p>Fr-SA-0100.01</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Assessment Type</p></td><td><p>New</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Assessment Template Name</p></td><td><p>ASSESSMENT TEMPLATE 05MAR19</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Entity Type</p></td><td><p>EntityType123</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>System Owner</p></td><td><p>stalin s[stalin]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Created On</p></td><td><p>2020-01-29 09:25:48 AM (UTC)</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Created By</p></td><td><p>stalin s[stalin]</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Assessment Template Details</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Assessment Template</p></td><td><p>ASSESSMENT TEMPLATE 05MAR19</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Code</p></td><td><p>Fr-SAT-0007.01</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>User Name</p></td><td><p>Kanaka Raju[raju]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Created On</p></td><td><p>2019-04-05 12:47:58 PM (UTC)</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Entity Type Details</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Task</p></td><td><p>EntityType123</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Prefix</p></td><td><p>ET123</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Code</p></td><td><p>Fr-ET-0040.01</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Is Building Required?</p></td><td><p>Yes</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Is Room Required?</p></td><td><p>Yes</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Is Department Required?</p></td><td><p>Yes</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Created By</p></td><td><p>cristiano 7[ronaldo]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Created On</p></td><td><p>2019-05-08 06:21:48 AM (UTC)</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Entity Form Type</p></td><td><p>Entity Form</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Assessment Template</p></td><td><p>ASSESSMENT TEMPLATE 05MAR19</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h2><a name='_Toc418583172'>Form Details</a></h2><br clear='all'/><p><strong> </strong></p><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td><p>Text1</p></td><td><p>123</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Entity Details</a></h1><h2><a name='_Toc418583172'>Enable User[Enable User]</a></h2><table border=1 cellpadding=0 cellspacing=0 width=95%><tbody><tr><td valign=top bgcolor=#eeeeee width=20%><p>Category</p></td><td valign=top bgcolor=#eeeeee width=20%><p>Sub Category</p></td><td valign=top bgcolor=#eeeeee width=20%><p>Entity Name</p></td><td valign=top bgcolor=#eeeeee width=20%><p>Entity No.</p></td><td valign=top bgcolor=#eeeeee width=20%><p>Intended Use</p></td></tr><tr><td><p>Cat01</p></td><td><p>SubCat02</p></td><td><p>Enable User</p></td><td><p>Enable User</p></td><td><p>N/A</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Section Details</a></h1><h2><a name='_Toc418583172'>MAN GXP 26MAR19 TEST1</a></h2><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Section Name</p></td><td><p>MAN GXP 26MAR19 TEST1</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Form Name</p></td><td><p>MAN STD Form 26MAR18 T1</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Performed By</p></td><td><p>stalin s[stalin]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Performed On</p></td><td><p>2020-01-29 09:26:15 AM (UTC)</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Completed By</p></td><td><p>stalin s[stalin]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Completed On</p></td><td><p>2020-01-29 09:26:32 AM (UTC)</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Section Result</p></td><td><p>GxP Impact</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>MAN STD Form 26MAR18 T1</a></h3><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td><p>TxtBx</p></td><td><p>WWWWWWWWWW</p></td></tr><tr><td><p>TxtArea</p></td><td><p>WWWW</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>Decision Tree Details</a></h3><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Decision Tree Name</p></td><td><p>GXP test decision tree</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Decision Type</p></td><td><p>GxP Assessment</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Prefix</p></td><td><p>GXP YesNo</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Scope</p></td><td><p>N/A</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Description</p></td><td><p>N/A</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>Assessment Decision</a></h3><table border=1 cellpadding=0 cellspacing=0 width=100%><tbody><tr><td valign=top bgcolor=#eeeeee width=5%><p>#</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Questions</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Answers</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Actions</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Justification</p></td></tr><tr><td rowspan=2><p>1</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35% rowspan = 2 ><p> q-q : qstion1 </p></td> <td valign=top bgcolor=#eeeeee width=25% Height=35%><p>A-1 : s</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p> End Action </p></td><td valign=top width=23%><p>N/A</p></td></tr><tr><td valign=top color='green' width=25%><p><font color='green'>A-2 : n</font></p></td><td valign=top color='green' width=25%><p><font color='green'> End Action </font></p></td><td valign=top color='green' width=23%><p><font color='green'>N/A</font></p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h2><a name='_Toc418583172'>sec_ip</a></h2><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Section Name</p></td><td><p>sec_ip</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Form Name</p></td><td><p>For Risk Form</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Performed By</p></td><td><p>stalin s[stalin]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Performed On</p></td><td><p>2020-01-29 09:26:45 AM (UTC)</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Completed By</p></td><td><p>stalin s[stalin]</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Completed On</p></td><td><p>2020-01-29 09:27:06 AM (UTC)</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Section Result</p></td><td><p>11-ll</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>For Risk Form</a></h3><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td><p>Text1</p></td><td><p>123</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>Decision Tree Details</a></h3><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Decision Tree Name</p></td><td><p>dtrisk_ip</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Decision Type</p></td><td><p>Risk Assessment</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Prefix</p></td><td><p>dtrisk_ip</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Scope</p></td><td><p>N/A</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Description</p></td><td><p>N/A</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>Risk Details</a></h3><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=5%><p>#</p></td><td valign=top bgcolor=#eeeeee width=35%><p>Risk Factor</p></td><td valign=top bgcolor=#eeeeee width=35%><p>Risk Value</p></td></tr><tr><td><p>1</p></td><td><p>f2</p></td><td><p>11-ll</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h3><a name='_Toc418583171'>Assessment Decision</a></h3><h4><a name='_Toc418583171'>f2</a></h4><table border=1 cellpadding=0 cellspacing=0 width=100%><tbody><tr><td valign=top bgcolor=#eeeeee width=5%><p>#</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Questions</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Answers</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Actions</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>Justification</p></td></tr><tr><td rowspan=2><p>1</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35% rowspan = 2 ><p> q1-q1 : q1 </p></td> <td valign=top color='green' width=25%><p><font color='green'>A-1 : y</font></p></td><td valign=top color='green' width=25%><p><font color='green'>s1-s1 : s1</font></p></td><td valign=top color='green' width=23%><p><font color='green'>N/A</font></p></td></tr><tr><td valign=top bgcolor=#eeeeee width=25% Height=35%><p>A-2 : n</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p> End Action </p></td><td valign=top width=23%><p>N/A</p></td></tr><tr><td rowspan=2><p>2</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35% rowspan = 2 ><p> s1-s1 : s1 </p></td> <td valign=top bgcolor=#eeeeee width=25% Height=35%><p>A-1 : a</p></td><td valign=top bgcolor=#eeeeee width=25% Height=35%><p> End Action </p></td><td valign=top width=23%><p>N/A</p></td></tr><tr><td valign=top color='green' width=25%><p><font color='green'>A-2 : b</font></p></td><td valign=top color='green' width=25%><p><font color='green'> End Action </font></p></td><td valign=top color='green' width=23%><p><font color='green'>N/A</font></p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Assessment Summary</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>MAN GXP 26MAR19 TEST1</p></td><td><p>GxP Impact</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>sec_ip</p></td><td><p>11-ll</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Business Rule Details</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Business Rule Name</p></td><td><p>Rule1</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Framework Deliverables</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=5%><p>#</p></td><td valign=top bgcolor=#eeeeee width=35%><p>Framework Id</p></td><td valign=top bgcolor=#eeeeee width=35%><p>Framework</p></td><td valign=top bgcolor=#eeeeee width=35%><p>Created On</p></td></tr><tr><td><p>1</p></td><td><p>Fr-VF-0001.01</p></td><td><p>Create &&framew</p></td><td><p>2019-06-19 10:34:00 AM (UTC)</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p><h1><a name=_Toc424545941>Validation Criteria</a></h1><table border=1 cellpadding=0 cellspacing=0 width=80%><tbody><tr><td valign=top bgcolor=#eeeeee width=35%><p>Based On</p></td><td><p>Framework</p></td></tr><tr><td valign=top bgcolor=#eeeeee width=35%><p>Entity Status Validation Rule</p></td><td><p>valodated</p></td></tr></tbody></table><br clear='all'/><p><strong> </strong></p>");

Thankstable_border_1.png (28.2 KB)

@Ramyamai

We have tested the scenario using the latest version of Aspose.Words for .NET 20.2 and have not found the shared issue. So, please use Aspose.Words for .NET 20.2.

Hi,

Thanks for your post. I am using latest version only.

i am using the sample template.In that template table of content as references will be binded.

below given code:
Aspose.Words.Document wdMainDoc = new Aspose.Words.Document(fileName.ToString());
DocumentBuilder builder = new DocumentBuilder(wdMainDoc);
builder.MoveToBookmark((wdMainDoc.Range.Bookmarks[5].Name), false, true);
builder.InsertHtml(docStructures.ToString());
wdMainDoc.UpdateFields();
wdMainDoc.Save(saveFilename);

I have attached the image.please take as reference and help out to display border.s1.png (153.8 KB)
s2.png (139.5 KB)

@Ramyamai

Could you please ZIP and attach problematic output and expected output Word documents here for our reference? We will then provide you more information about your query.

Hi,

I have attached zip files, i need to add border for each table in the problematic output which i attached one.

I think because of the logo in the header not getting border
if i remove logo in the header table borders are showing.

I have attached sample template alsoAspose_doubt.zip (85.5 KB)

Pls do the needful.

@Ramyamai

After opening the shared document in MS Word, we can see the table’s border. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Please take the screenshot of table that has border issue and attach it.
  • Please attach the expected output Word file that shows the desired behavior.

Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Thanks for the Reply.

For your information, I am using Microsoft Word 2010.
Document.zip (236.4 KB)
please do the needful.

@Ramyamai

We have not found the table’s border issue at our end in MS Word 2016. You can use following code example to set the table’s border. Hope this helps you.

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))
{
    table.ClearBorders();
    table.SetBorders(LineStyle.Single, 1.0, Color.Black);
}
doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2010);
doc.Save(MyDir + "20.2.docx");

Thanks for the Reply.

Its working fine now.
But i am getting table border for footer also. Except header and footer need to set table border.

kindly do the needful.Header_Footer_Issue.png (152.3 KB)

@Ramyamai

In your case, we suggest you please iterate over table’s nodes of Body node and set the table’s border. Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "input.docx");

foreach (Section section in doc.Sections)
{
    foreach (Table table in section.Body.GetChildNodes(NodeType.Table, true))
    {
        table.ClearBorders();
        table.SetBorders(LineStyle.Single, 1.0, Color.Black);
    }
}
                
doc.CompatibilityOptions.OptimizeFor(MsWordVersion.Word2010);
doc.Save(MyDir + "20.2.docx");

@tahir.manzoor

Thank you so much.

Its working fine now.