How to introduce a rowspan?

Category: 
Tags: tablesrowspaniText 7

I am adding a table to a PDF file. I have 3 rows and 3 columns. I want the first column to appear only once as a single cell for all the rows. The result should be like where it says Deloitte in the column of company as shown in the image:

Table showing desired result

Posted on StackOverflow on Apr 5, 2014 by sindhu jampani

The MyFirstTable example from iText in Action does exactly what you need. It looks like this:

// a table with three columns
Table table = new Table(3);
// the cell object
Cell cell;
// we add a cell with colspan 3
cell = new Cell(1, 3).add(new Paragraph("Cell with colspan 3"));
table.addCell(cell);
// now we add a cell with rowspan 2
cell = new Cell(2, 1).add(new Paragraph("Cell with rowspan 2"));
table.addCell(cell);
// we add the four remaining cells with addCell()
table.addCell("row 1; cell 1");
table.addCell("row 1; cell 2");
table.addCell("row 2; cell 1");
table.addCell("row 2; cell 2");

In your case you'd need cell = new Cell(1,6); for the cell with value Deloitte.

Click this link if you want to see how to answer this question in iText 5.