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

Free Support Forum - aspose.com

Cell.Width giving incorrect values with ColSpan

Hi,

I noticed that calling the cell.Width function is returning an incorrect value when a cell has the ColSpan property set. Shouldn’t Cell.Width take into account the colspan and return 200 for the merged cell in this case?

        Document doc = new Document();
        Page page = doc.Pages.Add();
        page.PageInfo.Width = PageSize.PageLetter.Width;
        page.PageInfo.Height = PageSize.PageLetter.Height;
        page.PageInfo.Margin = new MarginInfo(27, 27, 27, 27);

        var table = new Table()
        {
            ColumnWidths = "100 100 100",
            Border = new BorderInfo(BorderSide.All),
            DefaultCellBorder = new BorderInfo(BorderSide.All),
        };
        page.Paragraphs.Add(table);

        var row = table.Rows.Add();
        var mergedCell = row.Cells.Add();
        mergedCell.ColSpan = 2;
        var tfragment1 = new TextFragment("Test Cell Colspan 2");
        mergedCell.Paragraphs.Add(tfragment1);
        var cell = row.Cells.Add();
        var tFragment2 = new TextFragment("Test Cell colspan 1");
        cell.Paragraphs.Add(tFragment2);

        table.GetWidth();
        Debug.Assert(mergedCell.Width == 200);
        Debug.Assert(cell.Width == 100);

        doc.Save("CellWidthMerged.pdf");

@dfactset,
It is because the actual number of Cells in the Row are three. You can apply a check in the code to multiply column span number with the width of merged Cell. We hope, this helps. Kindly let us know in case of any further assistance or questions.

Best Regards,
Imran Rafique