Free Support Forum - aspose.com

RowSpan / ColumnsSpan not working as expected

I'm trying to create a table that has cells that use both the RowSpan and ColumnsSpan properties. See the following code:

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("");

Section section = pdf.Sections.Add();

section.Paragraphs.Add(new Text("Table Title"));
Table table = new Table();
section.Paragraphs.Add(table);

table.DefaultCellBorder = new BorderInfo((int)BorderSide.All, 0.1F);

Row row = table.Rows.Add();
Cell cell = row.Cells.Add("Cell A1");
cell.RowSpan = 2;

row.Cells.Add("Cell B1");
row.Cells.Add("Cell C1");
row = table.Rows.Add();

cell = row.Cells.Add("Cell B2");

cell.ColumnsSpan = 2;

I would expect a table where cell B2 spans B1 and C1 but it does not.

What's wrong with my code?

Hi,

Thank you for considering Aspose.

You need to specify the column width. I added a line "table.ColumnWidths = "100 100 100";" into your code then it works.

I will try to avoid the problem when using default column width.