Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java itext填充表_Java_Itext - Fatal编程技术网

Java itext填充表

Java itext填充表,java,itext,Java,Itext,我需要在第一列中填入一个数字,在第二列中填入数组中的某些数据 所以它看起来像: 1 |数据1 2 |数据2 3 |数据3 添加此数据的最佳方式是什么 通常你会做如下事情: Table table = new Table(3); table.setWidth(100); table.setDefaultVerticalAlignment(Element.ALIGN_TOP); table.setCellsFitPage(true);

我需要在第一列中填入一个数字,在第二列中填入数组中的某些数据

所以它看起来像:

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); }
然后你会得到这样的结果:

 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类可以在不再受支持的iText的较旧版本中找到。最新版本使用PdfPTable

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

我强烈建议您升级到最新版本,以获得所有最新功能、错误修复和安全修复。

这只是他的第一个问题,他还必须做排的事情。您应该立即转到3。是的,列不是问题所在。这是一个简单有效的解决方案!但是有一种方法可以在某些表字段中添加某些数据。像这样,你需要按正确的顺序填表。据我所知,你必须按顺序填表。我还没有尝试过,但也许您可以在表中定义一个单元格,然后在呈现pdf之前更改单元格中的文本,同样,如果不尝试,我也不确定。@DarthBlueRay在哪里定义了表类?我只能在Java SE 6文档中找到JTable?