如何使用Itext Java合并PDF中具有相同值的行

时间:2018-12-20 06:21:05

标签: java itext export-to-pdf

我正在处理PDF导出,并且有一个列表列表。我正在尝试创建具有this之类的合并单元格的PDF,但是由于PdfTable不允许我获取上一个行单元格以使用rowspan进行比较和合并,因此无法合并行。请以可行的逻辑帮助我。

try {
    List<List<Object>> tempcolumnList = new ArrayList<List<Object>>();
    PdfPTable pdfTable = new PdfPTable(headerList.size());
    PdfPCell cell;
    pdfTable.setWidthPercentage(100);
    for (String header : headerList) {
        cell = new PdfPCell(new Phrase(header, bold));
        cell.setBackgroundColor(new BaseColor(50, 139, 255));
        pdfTable.addCell(cell);
    }

    pdfTable.setHeaderRows(1);
    int j = 0;
    for (List<Object> colList : tempcolumnList) {
         int i = 0;
         for (Object rowData : colList) {
              rowData = (rowData == null)? "" :rowData.toString();
              cell = new PdfPCell(new Phrase((String) rowData, regular));
              i++;
              pdfTable.addCell(cell);
        }
    }

    return pdfTable;
} catch (Exception ex) {
    ex.printStackTrace();
}

0 个答案:

没有答案