【问题标题】:iTextpdf PdfPTable how to add cell in the any position in the grid?iTextpdf PdfPTable 如何在网格中的任何位置添加单元格?
【发布时间】:2015-01-05 15:23:37
【问题描述】:

我正在尝试将旧的 XLS 表生成器转换为 PDF 表生成器。而在 HSSFWOrkbook 中实际上可能在创建时设置单元格索引。但是我怎样才能对 PDF 中的 PdfPTable 做同样的事情呢? 只有方法可用 .addCell()。没有太多。

【问题讨论】:

    标签: java pdf cell xls


    【解决方案1】:

    您可以使用 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]);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 2013-02-10
      • 2016-04-05
      • 1970-01-01
      相关资源
      最近更新 更多