Table borders visible when using CellFormat.Borders.LineStyle = LineStyle.None

Hi,

When building a table the cell borders are visible even if CellFormat.Borders.LineStyle is set to LineStyle.None.
For reproducing the issue please use the following code:

var document = new Document();
var section = new Section(document);
section.ChildNodes.Add(new Body(document));
document.Sections.Add(section);

var table = new Table(document);

for (var i = 0; i < 5; i++)
{
    var wordRow = new Row(document);

    for (var j = 0; j < 5; j++)
    {
        var cell = new Cell(document);

        // making sure LineStyle = None.
        cell.CellFormat.Borders.LineStyle = LineStyle.None;

        var wordsParagraph = new Paragraph(document);
        var wordRun = new Run(document) { Text = Convert.ToString(j) };
        wordsParagraph.AppendChild(wordRun);
        cell.AppendChild(wordsParagraph);
        cell.CellFormat.Borders.ClearFormatting();
        wordRow.AppendChild(cell);
    }

    table.Rows.Add(wordRow);
}

section.Body.ChildNodes.Add(table);
document.Save("table.docx");

Regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi Aurelian,

Thanks for your inquiry. Please use Table.ClearBorders method to remove all table and cell borders on this table. See the highlighted code snippet below.

Please let us know if you have any more queries.

var document = new Document();
var section = new Section(document);
section.ChildNodes.Add(new Body(document));
document.Sections.Add(section);
var table = new Table(document);
for (var i = 0; i < 5; i++)
{
    var wordRow = new Row(document);
    for (var j = 0; j < 5; j++)
    {
        var cell = new Cell(document);
        // making sure LineStyle = None.
        cell.CellFormat.Borders.LineStyle = LineStyle.None;
        // cell.CellFormat.Borders.Top.ClearFormatting();
        var wordsParagraph = new Paragraph(document);
        var wordRun = new Run(document) { Text = Convert.ToString(j) };
        wordsParagraph.AppendChild(wordRun);
        cell.AppendChild(wordsParagraph);
        cell.CellFormat.Borders.ClearFormatting();
        wordRow.AppendChild(cell);
    }
    table.Rows.Add(wordRow);
}
section.Body.ChildNodes.Add(table);
table.ClearBorders();
document.Save(MyDir + "Out.docx");

Hi Tahir,

This would not resolve the issue, clearing all the borders of the table is not useful when I want for example to set only a single cell’s borders to LineStyle.None and it doesn’t work.
I can’t clear the entire table and then re-construct the borders of all the cells except the one which I want to have no borders. The fix of this issue would be to make LineStyle.None work properly, I mean when setting a cell’s border to LineStyle.None the respective border to disappear.

Best regards,
Aurelian Iordache
Software Developer
IBM Romania

Hi Aurelian,

Thanks for your inquiry.
Please use the following code example to set the line style of a specific table’s cell. Hope this helps you. Please let us know if you have any more queries.

var document = new Document();
var table = new Table(document);
for (var i = 0; i < 5; i++)
{
    var wordRow = new Row(document);
    for (var j = 0; j < 5; j++)
    {
        var cell = new Cell(document);
        var wordsParagraph = new Paragraph(document);
        var wordRun = new Run(document) { Text = Convert.ToString(j) };
        wordsParagraph.AppendChild(wordRun);
        cell.AppendChild(wordsParagraph);
        wordRow.AppendChild(cell);
        cell.EnsureMinimum();
    }
    table.Rows.Add(wordRow);
}
document.FirstSection.Body.ChildNodes.Add(table);
table.SetBorders(LineStyle.Single, 1.0, Color.Black);
Cell cell2 = table.FirstRow.Cells[1];
cell2.CellFormat.Borders.LineStyle = LineStyle.None;
cell2 = table.Rows[1].Cells[1];
cell2.CellFormat.Borders.LineStyle = LineStyle.None;
document.Save(MyDir + "Out.docx");

Hi Aurelian,

*ibmromania:

When building a table the cell borders are visible even if CellFormat.Borders.LineStyle is set to LineStyle.None.*

Further to my last post, I have logged this problem in our issue tracking system as WORDSNET-12114. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

The issues you have found earlier (filed as WORDSNET-12114) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(17)

Hello,

We have tested with the new version of Aspose Words and it now seems to be working properly.

Thank you!

Best regards,
Stanescu Jean-Alexandru
Junior Developer
IBM Romania