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

Free Support Forum - aspose.com

Cell merging not working as expected in tables

Hi,
I have created 2 tables. Each has 2 rows, row 1 (cells 1 and 2), row 2 (cells 3 and 4). I have created the first table using DocumentBuilder and the second using Table t = new Table(). I have an additional method that vertically merges cells 1 and 3. The method works for the first table but not for the second.
I need the tables to be absolutely positioned on the page so I was wanting to put them into text boxes so they can appear anywhere. That seemed to work fine until I tried to merge cells. I have attached my code. I upgraded to 5.3.0 yesterday. Am I merging incorrectly for the second table?

Hi
Thanks for your inquiry. Please try also set width of each cell in the table. See the following code:

private void FormatCells(Cell cell1, Cell cell2, Cell cell3, Cell cell4)
{
    cell1.EnsureMinimum();
    cell2.EnsureMinimum();
    cell3.EnsureMinimum();
    cell4.EnsureMinimum();
    cell1.Paragraphs[0].AppendChild(new Run(cell1.Document, "1"));
    cell2.Paragraphs[0].AppendChild(new Run(cell2.Document, "2"));
    cell3.Paragraphs[0].AppendChild(new Run(cell3.Document, "3"));
    cell4.Paragraphs[0].AppendChild(new Run(cell4.Document, "4"));
    cell1.CellFormat.Width = 20;
    cell2.CellFormat.Width = 20;
    cell3.CellFormat.Width = 20;
    cell4.CellFormat.Width = 20;
    cell1.CellFormat.VerticalMerge = CellMerge.First;
    cell2.CellFormat.VerticalMerge = CellMerge.None;
    cell3.CellFormat.VerticalMerge = CellMerge.Previous;
    cell4.CellFormat.VerticalMerge = CellMerge.None;
}

Hope this helps.
Best regards.

Hi,
Thanks for the quick reply. I have added the above lines and it fixes my issue for the moment. Thank-you.
Is there any way to get the cells to automatically resize? I’m not in a position to be able to caculate the desireable width at all times.

Hi
Thanks for your inquiry. You can also try to call UpdateTableLayout method before saving the document:

doc.UpdateTableLayout();

https://reference.aspose.com/words/net/aspose.words/document/updatepagelayout/
Hope this could help you.
Best regards.

Thank-you very much for your reply.
I am using the DocumentBuilder now which seems to solve my problem.