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.
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.
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.
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");
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).
There are three equivalent ways; pick the one you prefer.
if (targetTable != null)
{
targetTable.ClearBorders(); // removes top, bottom, left, right, inside… borders
}
Noneif (targetTable != null)
{
targetTable.Borders.LineStyle = LineStyle.None;
targetTable.Borders.Color = Color.Empty; // makes the line invisible
targetTable.Borders.LineWidth = 0;
}
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).
// Example: merge a list of objects
var data = new[]
{
new { Product = "Apple", Qty = 10 },
new { Product = "Banana", Qty = 5 }
};
doc.MailMerge.ExecuteWithRegions(data);
doc.Save("Report.docx");
| 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. |
If you still see borders after applying the above steps, please:
.docx) so we can inspect any hidden table style.Happy coding! ![]()
@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