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

huangapple go评论67阅读模式
英文:

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是一个叶子元素。实际文本由TextParagraph类型的对象表示:

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);

huangapple
  • 本文由 发表于 2020年9月7日 20:02:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/63777256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定