I am trying to add a gap between the bottom borders of two cells.
The following code does not work:
[TestMethod]
public void GenerateSpaceBetweenBorders()
{
Document doc = new Document();
// We can position where we want the table to be inserted and specify any extra formatting to the table.
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Font.Name = "Arial";
builder.Font.Size = 10d;
Table table = builder.StartTable();
void NewCell(string value, double preferredWidth)
{
builder.InsertCell();
builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(preferredWidth);
builder.Write(value);
}
// Row 1
NewCell("", 70d);
NewCell("", 30d);
builder.EndRow();
builder.EndTable();
table.Alignment = TableAlignment.Left;
// This setting is crucial - otherwise word recalculates the widths of the table columns as it desires
table.AllowAutoFit = false;
table.PreferredWidth = PreferredWidth.FromPercent(60);
table.SetBorders(LineStyle.None, 0, Color.Empty);
table.AllowCellSpacing = true; // enables spacing
table.CellSpacing = 3;
new List<Cell>
{
table.Rows[0].Cells[0],
table.Rows[0].Cells[1],
}.ForEach(cell =>
{
cell.CellFormat.Borders.Bottom.LineStyle = LineStyle.Single;
cell.CellFormat.Borders.Bottom.LineWidth = 1.0; // points
cell.CellFormat.Borders.Bottom.Color = Color.DarkGray;
// Other borders – leave unchanged or set to None if you prefer
cell.CellFormat.Borders.Top.LineStyle = LineStyle.None;
cell.CellFormat.Borders.Left.LineStyle = LineStyle.None;
cell.CellFormat.Borders.Right.LineStyle = LineStyle.None;
}
);
doc.Save(@"d:\temp\TestCellsBottomBorders.docx", SaveFormat.Docx);
}
The issue you’re encountering—where cell spacing (table.CellSpacing = 3; and table.AllowCellSpacing = true;) does not visibly create a gap between the bottom borders of adjacent cells when only bottom borders are applied—may be due to how Aspose.Words handles border rendering in table layouts, particularly with partial borders.
However, the visual gap may not appear as expected when only bottom borders are set. This behavior has been observed in earlier versions of Aspose.Words, where spacing between cells is not rendered correctly unless all borders are visible, due to internal border merging or collapsing logic.
A related issue was addressed in Aspose.Words for .NET 22.8 under ticket WORDSNET-13317, which resolved problems with cell spacing not being applied correctly in certain table configurations . Updating to Aspose.Words 22.8 or later is recommended, as this fix may resolve the spacing issue you’re experiencing.
Your code structure is correct and aligns with the intended API usage. The workaround you found in Microsoft Word—enabling “Allow spacing between cells” in table properties—corresponds directly to AllowCellSpacing and CellSpacing in Aspose.Words , confirming that your approach is valid.
If the issue persists after updating, consider testing with minimal content and verifying output in both Word and PDF to rule out rendering differences. Ensure no other formatting or border settings are interfering with the layout.
Since the execution failed, no code was run to validate the current behavior. The suggestion to update remains a hypothesis based on resolved issues in newer versions .
The user is asking for help with a specific code issue in Aspose.Words: spacing between bottom borders of adjacent cells is not rendering as expected, despite correct use of AllowCellSpacing and CellSpacing. The user provided code, described the actual vs expected behavior, and mentioned they are using version 25.8. This is a code-level troubleshooting scenario.