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

Free Support Forum - aspose.com

Wrong border line when merging

Hi,

If execute following code:

Document docMerge = new Document();
            
Table wordsTable = new Table(docMerge);
//row1
Aspose.Words.Tables.Row wordsRow1 = new Aspose.Words.Tables.Row(docMerge);
            
Aspose.Words.Tables.Cell wordsCell11 = new Aspose.Words.Tables.Cell(docMerge);
wordsCell11.CellFormat.Borders[Aspose.Words.BorderType.Bottom].LineStyle = Aspose.Words.LineStyle.Inset;
wordsCell11.CellFormat.Borders[Aspose.Words.BorderType.Bottom].Color = Color.Green;
wordsCell11.CellFormat.HorizontalMerge = CellMerge.First;
wordsRow1.AppendChild(wordsCell11);

Aspose.Words.Tables.Cell wordsCell12 = new Aspose.Words.Tables.Cell(docMerge);
wordsCell12.CellFormat.Borders[Aspose.Words.BorderType.Bottom].LineStyle = Aspose.Words.LineStyle.None;
wordsCell12.CellFormat.Borders[Aspose.Words.BorderType.Bottom].Color = Color.Red;
wordsCell12.CellFormat.HorizontalMerge = CellMerge.Previous;
wordsRow1.AppendChild(wordsCell12);

wordsTable.AppendChild(wordsRow1);
            
            
//row2
Aspose.Words.Tables.Row wordsRow2 = new Aspose.Words.Tables.Row(docMerge);
Aspose.Words.Tables.Cell wordsCell21 = new Aspose.Words.Tables.Cell(docMerge);
wordsCell21.CellFormat.Borders[Aspose.Words.BorderType.Top].LineStyle = Aspose.Words.LineStyle.Inset;
wordsCell21.CellFormat.Borders[Aspose.Words.BorderType.Top].Color = Color.Green;
wordsCell21.CellFormat.HorizontalMerge = CellMerge.None;
wordsRow2.AppendChild(wordsCell21);

Aspose.Words.Tables.Cell wordsCell22 = new Aspose.Words.Tables.Cell(docMerge);
wordsCell22.CellFormat.Borders[Aspose.Words.BorderType.Top].LineStyle = Aspose.Words.LineStyle.None;
wordsCell22.CellFormat.Borders[Aspose.Words.BorderType.Top].Color = Color.Red;
wordsCell22.CellFormat.HorizontalMerge = CellMerge.None;
wordsRow2.AppendChild(wordsCell22);

wordsTable.AppendChild(wordsRow2);

DocumentBuilder builder = new DocumentBuilder(docMerge);
builder.CurrentSection.Body.AppendChild(wordsTable);

wordsTable.AutoFit(AutoFitBehavior.FixedColumnWidths);
docMerge.Save("wrong border column.docx");
return;

The middle line is completely green but I expect the line in the second column to be ‘none’ as
you see in the code.

If I set Lifestyles to ‘Inlet’ instead of ‘None’, the same line becomes red. That is correct.

Is this a bug or what I’m doing wrong ?

Guido

@Nachti

Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.

cwrong border column.zip (16.0 KB)

Hi,

attached the wrong and correct version.

Kind regards,
Nachti

@Nachti

We have tested the scenario and managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22674. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

@Nachti

It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue WORDSNET-22674 as Not a Bug.

Please note that MS Word takes formatting from the first cell in the sequence. Aspose.Words’ behavior is same.

You should reset bottom border for the first row and set appropriate top borders in the last row to achieve the expected output. Following code example shows how to get the desired output.

Document doc = new Document();

Table wordsTable = new Table(doc);
//row1
Aspose.Words.Tables.Row wordsRow1 = new Aspose.Words.Tables.Row(doc);

Aspose.Words.Tables.Cell wordsCell11 = new Aspose.Words.Tables.Cell(doc);
wordsCell11.CellFormat.Borders[Aspose.Words.BorderType.Bottom].LineStyle = Aspose.Words.LineStyle.None;
wordsCell11.CellFormat.HorizontalMerge = CellMerge.First;
wordsRow1.AppendChild(wordsCell11);

Aspose.Words.Tables.Cell wordsCell12 = new Aspose.Words.Tables.Cell(doc);
wordsCell12.CellFormat.HorizontalMerge = CellMerge.Previous;
wordsRow1.AppendChild(wordsCell12);

wordsTable.AppendChild(wordsRow1);

//row2
Aspose.Words.Tables.Row wordsRow2 = new Aspose.Words.Tables.Row(doc);
Aspose.Words.Tables.Cell wordsCell21 = new Aspose.Words.Tables.Cell(doc);
wordsCell21.CellFormat.Borders[Aspose.Words.BorderType.Top].LineStyle = Aspose.Words.LineStyle.Inset;
wordsCell21.CellFormat.Borders[Aspose.Words.BorderType.Top].Color = Color.Green;
wordsCell21.CellFormat.Borders[Aspose.Words.BorderType.Top].LineWidth = 0.5;
wordsCell21.CellFormat.HorizontalMerge = CellMerge.None;
wordsRow2.AppendChild(wordsCell21);

Aspose.Words.Tables.Cell wordsCell22 = new Aspose.Words.Tables.Cell(doc);
wordsCell22.CellFormat.Borders[Aspose.Words.BorderType.Top].LineStyle = Aspose.Words.LineStyle.None;
wordsCell22.CellFormat.HorizontalMerge = CellMerge.None;
wordsRow2.AppendChild(wordsCell22);

wordsTable.AppendChild(wordsRow2);

DocumentBuilder builder = new DocumentBuilder(doc);
builder.CurrentSection.Body.AppendChild(wordsTable);

wordsTable.AutoFit(AutoFitBehavior.FixedColumnWidths);

doc.Save(MyDir + "21.9.docx");