简体   繁体   English

itext填充表

[英]itext filling table

I need to fill a table with in the first column a number and in the second column certain data from a array. 我需要在第一列中填充数字,在第二列中填充数组中的某些数据。

So it will look like : 所以它看起来像:

1 | 1 | Data1 数据1

2 | 2 | Data2 数据2

3 | 3 | Data3 数据3

What is the best way to add this data. 添加此数据的最佳方法是什么。

Usualy you do something like : 通常您会执行以下操作:

 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); }

Then you get something like : 然后您会得到类似:

Data 1 | 数据1 | Data 2 | 数据2 | Data 3 数据3

Data 4 | 数据4 | Data 5 | 数据5 | Data 6 数据6

Is there a specific way to fill selected cells or do I see it wrong. 有没有一种特定的方法来填充选定的单元格,还是我看错了?

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 );
}

As a sidenote : the Table class can be found in rather old versions of iText that are not supported anymore. 附带说明:Table类可以在不再受支持的iText的较旧版本中找到。 Most recent versions make use of PdfPTable. 最新版本使用PdfPTable。

I warmly recommend you to upgrade to a more recent version in order to get all the latest features, bug fixes and security fixes. 我热烈建议您升级到最新版本,以获取所有最新功能,错误修复和安全修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM