gpt4 book ai didi

java - iTextpdf PdfPTable 如何在网格中的任意位置添加单元格?

转载 作者:行者123 更新时间:2023-11-30 03:36:30 26 4
gpt4 key购买 nike

我正在尝试将旧的 XLS 表格生成器转换为 PDF 表格生成器。在 HSSFWOrkbook 中,实际上可以在创建时设置单元格索引。但是如何对 PDF 中的 PdfPTable 执行相同操作呢?唯一可用的方法是.addCell()。不是太多。

最佳答案

您可以使用 PdfCell 数组来做到这一点:

ncols = 6; // number of columns
nrows = 8; // number of rows
Pdfcell[][] cells = new PdfCell[nrows][ncols];

// To create the table cells
for(int icol=0; icol<ncols; icol++) {
for(int irow=0; irow<nrows; irow++) {
cells[irow][icol] = new PdfCell(new Phrase(
"Col:" + icol + ", Row:" + irow));
}
}

// To add the cells to table
for(int irow=0; irow<nrows; irow++) {
for(int icol=0; icol<ncols; icol++) {
table.addCell(cells[irow][icol]);
}
}

关于java - iTextpdf PdfPTable 如何在网格中的任意位置添加单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27782551/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com