使用itext创建rtf文件时出现了一个问题。 使用colspan的单元格未在输出文件中正确生成。 有人可以帮我弄这个吗。 我附上示例代码供参考。{无法附加图片:需要10个声誉}
public static void main( String[] args )
{
Document document = new Document( PageSize.A4, 50, 50, 50, 50 );
try
{
RtfWriter2 writer = RtfWriter2.getInstance( document, new FileOutputStream( "/root/Desktop/TableRtf.rtf" ) );
document.open();
Table table1 = new Table( 3 );
table1.setWidth( 100 );
table1.setBorder( 0 );
table1.getDefaultCell().setHorizontalAlignment( Element.ALIGN_CENTER );
table1.getDefaultCell().setVerticalAlignment( Element.ALIGN_MIDDLE );
table1.addCell( "!" );
table1.addCell( new Phrase( new Chunk( "cell" ) ) );
table1.addCell( "!" );
table1.addCell( "2" );
table1.addCell( new Phrase( new Chunk( "cell" ) ) );
table1.addCell( "2" );
table1.addCell( "3" );
table1.addCell( new Phrase( new Chunk( "cell" ) ) );
table1.addCell( "3" );
Table table = new Table( 2 );
table.setWidth( 100 );
table.setBorder( 0 );
com.lowagie.text.Cell tablecell1 = new com.lowagie.text.Cell();
tablecell1.addElement( new Chunk( "!!!!!!!!!!" ) );
tablecell1.setColspan( 2 );
table.addCell( tablecell1 );
table.addCell( "Text Text Text Text Text Text " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Text Text " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Text Text Text " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Text \nText \nText " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Text " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Text " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Text " );
table.addCell( new Phrase( new Chunk( "cell" ) ) );
table.addCell( "Table11 " );
table.insertTable( table1 );
document.add( table );
}
catch ( Exception de )
{
de.printStackTrace();
}
document.close();
}