cell.add(“cell content”)在itext7 7.1.12版本中不起作用这是我的还是itext7的?这里有一些代码

ej83mcc0  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(291)
Cell SubTitle = new Cell().setBold();
Cell CA1Title = new Cell().setBold().setTextAlignment(TextAlignment.CENTER);
Cell CA2Title = new Cell().setBold().setTextAlignment(TextAlignment.CENTER);
Cell ExamTitle = new Cell().setBold().setTextAlignment(TextAlignment.CENTER);
Cell TotalTitle = new Cell().setBold().setTextAlignment(TextAlignment.CENTER);
Cell RemarkTitle = new Cell().setBold();
SubTitle.add("Subject");
CA1Title.add("1st C.A");
CA2Title.add("2nd C.A");
ExamTitle.add("Exam");
TotalTitle.add("Total Score");
RemarkTitle.add("Remark");

方法 Cell.add() 不接受论点( String ).
有什么问题?

hi3rlvi2

hi3rlvi21#

在itext中,并非所有元素都只能接受“简单”文本—有些元素是其他“块”元素的容器,而 Text 是叶元素。实际文本由对象表示 Text 或者 Paragraph 类型:

Text text1 = new Text("Text 1");
Paragraph p1 = new Paragraph(text1);
Paragraph p2 = new Paragraph("Text 2");

这个 Cell 它本身(正如它的文档所说)只是一个容器,其中包含其他元素(并为表提供列/行扩展)。所以要添加文本,你需要给它一个 Paragraph 要保持的元素:

Cell myCell = new Cell()
    .add(new Paragraph("My Cell Title"))
    .setBold()
    .setTextAlignment(TextAlignment.CENTER);

相关问题