Di seguito il codice,
quello che vorrei ottenere è che A1 prenda il posto di A2 e B2
quindi unire le celle (1.1 - 1.2 - 2.1 - 2.2) e metterci dentro il valore A1 al centro.
codice:
import java.awt.Color;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class Esempio {
public static final String RESULT= "c:/test.pdf";
public static void main(String[] args)
throws IOException, DocumentException {
new Esempio().createPdf(RESULT);
}
public void createPdf(String filename)
throws IOException, DocumentException {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
document.add(getHeader());
document.close();
}
public static PdfPTable getHeader(){
PdfPTable table = new PdfPTable(11);
table.setWidthPercentage(100);
table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell c1 = getCell("A1",2,1);
c1.setBorderColorBottom(Color.BLUE);
table.addCell(c1);
table.addCell(getCell("B1",2,1));
table.addCell(getCell("C1",4,1));
table.addCell(getCell("D1",3,1));
table.addCell(getCell("A2",1,1));
table.addCell(getCell("B2",1,1));
table.addCell(getCell("C2"));
table.addCell(getCell("D2"));
table.addCell(getCell("E2"));
table.addCell(getCell("F2"));
table.addCell(getCell("G2"));
table.addCell(getCell("H2"));
table.addCell(getCell("I2"));
table.addCell(getCell("L2"));
table.addCell(getCell("M2"));
table.addCell(getCell("1"));
table.addCell(getCell("2"));
table.addCell(getCell("3"));
table.addCell(getCell("4"));
table.addCell(getCell("5"));
table.addCell(getCell("6"));
table.addCell(getCell("7"));
table.addCell(getCell("8"));
table.addCell(getCell("9"));
table.addCell(getCell("10"));
table.addCell(getCell("11"));
return table;
}
private static PdfPCell getCell(String text) {
return getCell(text, 1, 1);
}
private static PdfPCell getCell(String text, int colSpan, int rowSpan) {
Font font=new Font();
font.setColor(Color.WHITE);
Phrase ph=new Phrase(text,font);
PdfPCell tmpcell = new PdfPCell(ph);
tmpcell.setHorizontalAlignment(1);
tmpcell.setRowspan(rowSpan);
tmpcell.setColspan(colSpan);
tmpcell.setBackgroundColor(Color.BLUE);
tmpcell.setPaddingBottom(8);
return tmpcell;
}
}