Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTextSharp : merge the last column (Colspan)

I have a table, this table has 3 columns. In each column, there is a table like the picture. I did a method to generate table, this method receive a list in argument and loop on it to addCell to the table

I'd like for a line has a instead of 5 columns ... 1 + 1 (colspan of 4). When I do a colspan the 4 first are merged, I'd like merged the 4 last and keep the first.

How can I do this ?

Thanks,

enter image description here enter image description here

like image 838
Kris-I Avatar asked Feb 03 '26 15:02

Kris-I


1 Answers

You just need to add the cells to the table in the order that you want them to span. If you add the spanned cells before the first cell then that's how they'll appear.

PdfPTable t = new PdfPTable(5);
//Row 1
t.AddCell("R1C1");
t.AddCell("R1C2");
t.AddCell("R1C3");
t.AddCell("R1C4");
t.AddCell("R1C5");

//Row 2 - One regular cell followed by four spanned cells
t.AddCell("R2C1");
t.AddCell(new PdfPCell(new Phrase("R2C2-5")) { Colspan = 4 });

//Row 3 - Four spanned cells followed by one regular cell
t.AddCell(new PdfPCell(new Phrase("R3C1-4")) { Colspan = 4 });
t.AddCell("R3C5");
like image 85
Chris Haas Avatar answered Feb 05 '26 04:02

Chris Haas