2017-08-12 18 views
0

mit meinem Code, den ich dir oben zeige, bekomme ich auf die Reihe Artikel (siehe Bilder bitte) Name: 1 Name: 2 Name: 3 während ich möchte, dass diese Artikel auf dem gleichen (ersten) bleiben Spalte ... Wer kann mir helfen?Ausgabe für cicle

enter image description here

PdfPCell cell; 
PdfPTable table = new PdfPTable(3); 

cell = new PdfPCell(new Phrase("Item Name")); 
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_LEFT); 
cell.setBorder(Rectangle.NO_BORDER); 
table.addCell(cell); 

cell = new PdfPCell(new Phrase("Quantità")); 
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER); 
cell.setBorder(Rectangle.NO_BORDER); 
table.addCell(cell); 

cell = new PdfPCell(new Phrase("€")); 
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_RIGHT); 
cell.setBorder(Rectangle.NO_BORDER); 
table.addCell(cell); 
table.setHeaderRows(1); 

for (int i=1;i<5;i++) { 
    table.addCell("Name:" + i); 
    cell.setBorder(Rectangle.NO_BORDER); 
} 

Antwort

0

Ich glaube, Sie colspan wie so verwenden können:

PdfPCell cell; 
PdfPTable table = new PdfPTable(3); 

cell = new PdfPCell(new Phrase("Item Name")); 
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_LEFT); 
cell.setBorder(Rectangle.NO_BORDER); 
table.addCell(cell); 

cell = new PdfPCell(new Phrase("Quantità")); 
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_CENTER); 
cell.setBorder(Rectangle.NO_BORDER); 
table.addCell(cell); 

cell = new PdfPCell(new Phrase("€")); 
cell.setHorizontalAlignment(com.lowagie.text.Element.ALIGN_RIGHT); 
cell.setBorder(Rectangle.NO_BORDER); 
table.addCell(cell); 
table.setHeaderRows(1); 

for (int i=1;i<5;i++) { 
    // we add a cell with colspan 3 
    cell = new PdfPCell(new Phrase("Name:" + i)); 
    cell.setColspan(3); 
    cell.setBorder(Rectangle.NO_BORDER); 
    table.addCell(cell); 
} 
+0

es funktioniert! Warum?? – androidiano

+0

Ein Colspan dehnt die Spalte so lange wie Sie wollen, es gibt auch rowspan, dass strechws auf Zeile –

+1

Warum verwenden Sie immer noch 'com.lowagie.text'? Alle iText-Pakete mit meinem Namen im Paketnamen sollten nicht mehr verwendet werden. –