使用 iText 在 PDF 中为整个表格行着色的最简单方法是什么?目前我下面的代码只为表格中的特定单元格着色,但我不确定如何使整行着色。
如果有人能告诉我这是如何完成的,我将不胜感激,但请不要发布任何代码!我想自己做代码。谢谢
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
PdfPCell cell = new PdfPCell(new Phrase(myJTable.getValueAt(i, j).toString(), myFont));
if (phrase.toString().contains("Test")) {
cell.setBackgroundColor(BaseColor.RED); //I want to change the colour of
//the entire row containing a cell called "Test", not only the cell itself
}
pdfTable.addCell(cell);
}
}
最佳答案
如果您已经有了 PdfPRow
对象,则需要对其调用 getCells()
,然后遍历返回的单元格,设置每个单元格的颜色。
如果你还没有PdfPRow
,你可以通过PdfPCell
的getTable
方法和getRow获取
PdfPTable
的方法。
关于java - iText 在表格中制作一整卷彩色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22619740/