英文:
the Cell.add(" Cell Content ") does not work in Itext7 version 7.1.12 . is is this from me or from the Itext7 ? here are some codes
问题
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");
The method `Cell.add()` doesn't accept argument(`String`).
What is the problem?
英文:
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");
The method Cell.add()
doesn't accept argument(String
).
What is the problem?
答案1
得分: 2
在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);
英文:
In iText, not all elements can accept just "simple" text - some elements are containers for other "Block" elements, whereas the Text
is a Leaf element. Actual text is represented by objects of Text
or Paragraph
type:
Text text1 = new Text("Text 1");
Paragraph p1 = new Paragraph(text1);
Paragraph p2 = new Paragraph("Text 2");
The Cell
itself (as its documentation says) is simply a container that holds other elements (and provides col/row spanning for Tables). So to add text to it you need to give it a Paragraph
element to hold onto:
Cell myCell = new Cell()
.add(new Paragraph("My Cell Title"))
.setBold()
.setTextAlignment(TextAlignment.CENTER);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论