[英]itext filling table
我需要在第一列中填充數字,在第二列中填充數組中的某些數據。
所以它看起來像:
1 | 數據1
2 | 數據2
3 | 數據3
添加此數據的最佳方法是什么。
通常您會執行以下操作:
Table table = new Table(3);
table.setWidth(100);
table.setDefaultVerticalAlignment(Element.ALIGN_TOP);
table.setCellsFitPage(true);
table.setPadding(2);
table.setSpacing(0);
for (int i = 1; i <= 6; i++) {
Cell cell = new Cell("Data " + i);
table.addCell(cell); }
然后您會得到類似:
數據1 | 數據2 | 數據3
數據4 | 數據5 | 數據6
有沒有一種特定的方法來填充選定的單元格,還是我看錯了?
Table table = new Table( 2 ); // 2 is the number of columns
table.setWidth( 100 );
table.setDefaultVerticalAlignment( Element.ALIGN_TOP ) ;
table.setCellsFitPage( true );
table.setPadding( 2 );
table.setSpacing( 0 );
for ( int i = 1 ; i <= 3 ; i++ )
{
Cell leftCell = new Cell( i );
Cell rightCell = new Cell( "Data " + i );
table.addCell( leftCell );
table.addCell( rightCell );
}
附帶說明:Table類可以在不再受支持的iText的較舊版本中找到。 最新版本使用PdfPTable。
我熱烈建議您升級到最新版本,以獲取所有最新功能,錯誤修復和安全修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.