此模型接下来提供表格行中插入列的数据。研究了http://itextpdf.com/book/examples.php中的几个例子,但都没有说明当数据来自数据集并转换为HashMap时应该如何处理:
PdfPTable tabela = new PdfPTable(columnNumber);
PdfPCell celula;
for (Entry<String, List<String>> item : matriz.entrySet()) {
for (String linha : item.getValue()) {
celula = new PdfPCell(new Phrase(linha, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
tabela.addCell(celula);
dadosColuna.add(linha);
}
}
我尝试以下示例,其中列表数据被插入到单元格中。然而,有趣的是每一个都是在一个单独的细胞中给出的。
然后我尝试了以下内容:
// Imprimir linhas para cada chave/Coluna do Map
for (Entry<String, List<String>> item : matriz.entrySet()) {
for (String linha : item.getValue()) {
// celula = new PdfPCell(new Phrase(linha, FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD)));
// tabela.addCell(celula);
dadosColuna.add(linha);
}
// Envolve esta linha em uma frase
Phrase phrase = new Phrase();
for(int i = 0; i < dadosColuna.size(); i++)
phrase.add(dadosColuna.get(i).toString());
// phrase.add(dadosColuna.toString());
PdfPCell phraseCell = new PdfPCell();
phraseCell.addElement(phrase);
// Adiciona a celula a tabela
PdfPTable phraseTable = new PdfPTable(numeroColunas);
phraseTable.setSpacingBefore(5);
phraseTable.addCell(phraseCell);
// Aplica a frase em uma outra tabela
Phrase phraseTableWrapper = new Phrase();
phraseTableWrapper.add(phraseTable);
}
行中有错误:phraseTable.addCell(phraseCell);
即使不成功,列出HashMap带来的每次迭代都只会暴露在一个单元格中。我想在脊柱的相应单元格中输入每个项目。示例:当前问题是:heading 1, heading 2, heading 3 = OK!
given column 1, column data 1, as column 1, column 2 data given column 2, ...
我试图将此解决方案应用于此问题: http://itextpdf.com/sandbox/tables/ListInCell