微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Cell.add“ Cell Content”在Itext7版本7.1.12中不起作用是我还是Itext7提供的?这是一些代码

如何解决Cell.add“ Cell Content”在Itext7版本7.1.12中不起作用是我还是Itext7提供的?这是一些代码

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

出什么问题了?

解决方法

在iText中,并非所有元素都只能接受“简单”文本-一些元素是其他“ Block”元素的容器,而Text是Leaf元素。实际文本由TextParagraph类型的对象表示:

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

Cell本身(如其documentation所说)只是一个容纳其他元素的容器(并为Tables提供了col / row跨度)。因此,要向其中添加文本,您需要为其提供一个Paragraph元素以保持:

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。