About table border visibility in aspose word template using LINQ

Hi,

How to remove border from a table in aspose word template. Even after no border set in table it’s showing border while generate report. As part of alignment uniformity, we have inserted table and add field inside it.

@rose.thomas

Removing Table Borders in a Word Template (Aspose.Words .NET)

When a table appears with borders even though no border is defined in the template, the most common cause is that the table inherits a built‑in style (e.g., Table Grid) that has visible borders.
The fix is to clear the style or explicitly set the borders to None before you execute the LINQ‑based mail‑merge.

Below is a complete, step‑by‑step example that you can drop into your project.


1. Load the template

using Aspose.Words;
using Aspose.Words.Tables;
using System.Drawing;          // for Color.Empty
using System.Linq;

// Load the .docx that contains the placeholder table
Document doc = new Document("Template.docx");

2. Find the table(s) you want to modify

If you have only one table that contains the merge fields you can locate it with LINQ, e.g.:

// All tables that contain at least one merge field
Table targetTable = doc.GetChildNodes(NodeType.Table, true)
                       .Cast<Table>()
                       .FirstOrDefault(t => t.Range.Fields
                                               .Any(f => f.Type == FieldType.FieldMergeField));

If you need to edit all tables, simply iterate over doc.GetChildNodes(NodeType.Table, true).

3. Remove the borders

There are three equivalent ways; pick the one you prefer.

a) Clear all borders at once

if (targetTable != null)
{
    targetTable.ClearBorders();   // removes top, bottom, left, right, inside… borders
}

b) Set each border to None

if (targetTable != null)
{
    targetTable.Borders.LineStyle = LineStyle.None;
    targetTable.Borders.Color     = Color.Empty;   // makes the line invisible
    targetTable.Borders.LineWidth = 0;
}

c) Remove the table style that forces borders

if (targetTable != null)
{
    // Remove any applied style (e.g., “Table Grid”)
    targetTable.Style = null;               // or targetTable.StyleName = "";
    // Optionally keep other style options but disable borders
    targetTable.StyleOptions &= ~TableStyleOptions.Borders;
}

Tip: If the table inherits its appearance from a document‑wide style, you may also need to clear that style in the template itself (open the .docx, select the table → Table Tools → Design → Clear All).

4. Perform the LINQ‑based mail merge (if you haven’t done it yet)

// Example: merge a list of objects
var data = new[]
{
    new { Product = "Apple",  Qty = 10 },
    new { Product = "Banana", Qty = 5  }
};

doc.MailMerge.ExecuteWithRegions(data);

5. Save the result

doc.Save("Report.docx");

Quick Checklist

:white_check_mark: Item
Template – Ensure the table has no style that adds borders (clear style in Word).
Code – Call ClearBorders() or set Borders.LineStyle = LineStyle.None.
LINQ – Locate the correct table with doc.GetChildNodes(NodeType.Table, true).Cast<Table>().
Save – Write the output document after the border removal.

References


If you still see borders after applying the above steps, please:

  1. Attach the original template (.docx) so we can inspect any hidden table style.
  2. Confirm whether the borders appear before or after the mail‑merge step.

Happy coding! :tada:

@rose.thomas Could you please attach your actual template and output documents here for our reference? unfortunately, screenshots does not give enough information for analysis. I suspect that not all borders are disabled in the template and they become visible after filling the document with data.

Hi,

Issue fixed now. Thank you

1 Like