We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Clearing cell borders does not work

The following test should produce a word document where the first cell has a border and the second cell does not. In actuality, both cells have borders on all four sides.

Resulting document: BorderRepro.docx (17.6 KB)

[TestMethod]
public void AsposeRepro()
{
   Document doc = new Document();
   DocumentBuilder builder = new DocumentBuilder(doc);

   builder.StartTable();

   builder.InsertCell();
   builder.Write("With border");

   builder.InsertCell().CellFormat.Borders.ClearFormatting();
   builder.Write("No border");

   builder.EndTable();

   doc.Save(Path.Combine(OutputDirectory, "BorderRepro.docx"));
}

This is using Aspose.Words 21.6.0 on .NET 5.

@sam.magura

Please set the table’s cell border as shown below to get the desired output.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();
builder.InsertCell();
builder.Write("With border");


Cell cell = builder.InsertCell();
cell.CellFormat.Borders.LineStyle = LineStyle.None;
builder.Write("No border");

builder.EndTable();
doc.Save(MyDir + "21.6.docx");

Thank you @tahir.manzoor! It worked.

@sam.magura

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

@sam.magura

You may also use the following approach to achieve your requirement by clearing row formatting.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = builder.StartTable();
table.SetBorders(LineStyle.None, 0.0, Color.Black);
builder.RowFormat.ClearFormatting();
Cell cell0 = builder.InsertCell();

// Set cell borders
cell0.CellFormat.Borders.Color = Color.Black;
cell0.CellFormat.Borders.LineWidth = 3;
builder.Write("With border");


Cell cell = builder.InsertCell();
cell.CellFormat.Borders.ClearFormatting();

// Clear row orders
cell.ParentRow.RowFormat.Borders.ClearFormatting();
builder.Write("No border");

builder.EndTable();

doc.Save("C:\\Temp\\21.6.docx");