itext填表 [英] itext filling table
本文介绍了itext填表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在第一列中填写一个数字,在第二列中填充数组中的某些数据。
I need to fill a table with in the first column a number and in the second column certain data from a array.
所以它看起来像:
1 |数据1
2 |数据2
3 |数据3
添加此数据的最佳方式是什么。
What is the best way to add this data.
通常你会这样做:
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 :
数据1 |数据2 |数据3
Data 1 | Data 2 | Data 3
数据4 |数据5 |数据6
Data 4 | Data 5 | Data 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 );
}
这篇关于itext填表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文