Free Support Forum - aspose.com

Rowspan issue

I think there is an issue with using rowspan in a table with colspan.

Take the following code:

var tmpLayoutTestTable = new Table
            {
                Border = new BorderInfo(BorderSide.All, .5f,
                    Color.FromRgb(System.Drawing.Color.LightGray)),
                DefaultColumnWidth = "50",
                DefaultCellPadding = new MarginInfo(2f, 2f, 0f, 2f),
            };

            var tmpRow1 = tmpLayoutTestTable.Rows.Add();

            tmpRow1.Cells.Add(new Cell()
            {
                ColSpan = 2,
                BackgroundColor = Color.Red
            });

            tmpRow1.Cells.Add(new Cell()
            {
                //ColSpan = 2,
                BackgroundColor = Color.Red
            });

            tmpRow1.Cells.Add(new Cell
            {
                BackgroundColor = Color.Green,
                RowSpan = 2
            });

            tmpRow1.Cells.Add(new Cell
            {
                BackgroundColor = Color.Yellow,
                //ColSpan = 3
            });

            tmpRow1.Cells.Add(new Cell
            {
                ColSpan = 8,
                BackgroundColor = Color.Pink
            });


            var tmpRow2 = tmpLayoutTestTable.Rows.Add();
            tmpRow2.Cells.Add(new Cell()
            {
                ColSpan = 2,
                BackgroundColor = Color.Blue
            });

            tmpRow2.Cells.Add(new Cell()
            {
                //ColSpan = 2,
                BackgroundColor = Color.Blue
            });

            tmpRow2.Cells.Add(new Cell
            {
                BackgroundColor = Color.Blue,
                //ColSpan = 3
            });

            tmpRow2.Cells.Add(new Cell
            {
                ColSpan = 8,
                BackgroundColor = Color.Pink
            });

As of my expectations, the blue cell should be the same length as the red cell. This is not the case.

Aspose.PDF 18.8.0

Could you confirm that?

@newwin-sws

Thanks for contacting support.

We have checked the code snippet shared by you and noticed that the Red Cells were capturing three columns (first with colspan = 2 and second with single cell) . Whereas in the second row Blue Cells were consisting of total 4 cells (firs with colspan = 2 and second/third with single cell) which was why you were observing the difference in output. Please change last Blue Cell to some different color to equalize both rows and you will see the expected output. tempTable.pdf (1.7 KB)

var tmpLayoutTestTable = new Table
{
                Border = new BorderInfo(BorderSide.All, .5f,
                    Color.FromRgb(System.Drawing.Color.LightGray)),
                DefaultColumnWidth = "50",
                DefaultCellPadding = new MarginInfo(2f, 2f, 0f, 2f),
 };

var tmpRow1 = tmpLayoutTestTable.Rows.Add();

tmpRow1.Cells.Add(new Cell()
{
   ColSpan = 2,
  BackgroundColor = Color.Red
});

tmpRow1.Cells.Add(new Cell()
{
  //ColSpan = 2,
  BackgroundColor = Color.Red
});

tmpRow1.Cells.Add(new Cell
{
  BackgroundColor = Color.Green,
 RowSpan = 2
});

tmpRow1.Cells.Add(new Cell
{
 BackgroundColor = Color.Yellow,
 //ColSpan = 3
});

tmpRow1.Cells.Add(new Cell
{
ColSpan = 8,
BackgroundColor = Color.Pink
});


var tmpRow2 = tmpLayoutTestTable.Rows.Add();
tmpRow2.Cells.Add(new Cell()
{
   ColSpan = 2,
   BackgroundColor = Color.Blue
});

tmpRow2.Cells.Add(new Cell()
{
 //ColSpan = 2,
 BackgroundColor = Color.Blue
});

tmpRow2.Cells.Add(new Cell
{
   BackgroundColor = Color.Yellow,
   //ColSpan = 3
});

tmpRow2.Cells.Add(new Cell
{
                ColSpan = 8,
                BackgroundColor = Color.Pink
});