- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想让 XWPFParagraph
(开始)内的文本成为指向文档中另一个具体 XWPFParagraph
(结束)的超链接。我找到了在 XWPFCell
内创建超链接的代码,但它不起作用(启动链接开始):
private static void createHyperlink(XWPFParagraph start, XWPFParagraph end, String endText, String startText) {
CTHyperlink cLink = end.getCTP().addNewHyperlink();
cLink.setAnchor(startText);
CTText ctText = CTText.Factory.newInstance();
ctText.setStringValue(endText);
CTR ctr = CTR.Factory.newInstance();
ctr.setTArray(new CTText[] { ctText });
cLink.setRArray(new CTR[] { ctr });
start.getCTP().setHyperlinkArray(new CTHyperlink[] { cLink });
end.getCTP().removeHyperlink(0);
}
最佳答案
我终于做到了。最初的想法是创建一个从 XWPFParagraph 到另一个 XWPFParagraph 的超链接,但由于我总是链接到文档中具有唯一文本的段落,所以我发现了这种方式:
private static void createHyperLink(XWPFParagraph start, String startTxt, String endTxt) {
// Creating the hyperlink in the start paragraph
CTHyperlink cLink = start.getCTP().addNewHyperlink();
// Link to the end text in the doc
cLink.setAnchor(endTxt);
// Creating the String that will have the hyperlink
CTText ctText = CTText.Factory.newInstance();
ctText.setStringValue(startTxt);
CTR ctr=CTR.Factory.newInstance();
ctr.setTArray(new CTText[]{ctText});
// Inserting the String in the doc
cLink.setRArray(new CTR[]{ctr});
}
关于java - 将 XWPFParagraph 的超链接插入到 XWPFDocument 中的另一个段落,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48183649/
最初我有一个 DOCX 模板文档。所以我得到org.apache.poi.xwpf.usermodel.XWPFDocument 出来,假设它有 5 个 XWPFParagraph,例如:
我正在尝试使用 Apache POI 从 Microsoft Word 文档中删除一组连续的段落。 据我了解,可以通过删除段落的所有运行来删除段落,方法如下: /* * Deletes the gi
读取docx文件并尝试存储在字符串变量中下面是我的代码 try { File file = new File(fileName); FileInputS
你知道是否有办法在段落填充文档 (XWPFDocument) 中插入段落 (XWPFParagraph) 吗? 有一种方法可以将文档中已经存在的段落“更改”为另一个段落 (XWPFDocument.s
我想让 XWPFParagraph(开始)内的文本成为指向文档中另一个具体 XWPFParagraph(结束)的超链接。我找到了在 XWPFCell 内创建超链接的代码,但它不起作用(启动链接开始):
我已经能够遍历文档中的所有段落并获得文本和所有内容,并且我已经阅读并理解了如何从头开始创建文档。但是我怎样才能更新和替换段落中的文本呢?我可以在段落中执行 createRun,但这只会在其中创建一段新
我正在迭代来自 XWPTDocument 实例的 XWPFParagraph 实例(使用“getParagraphs()”方法) 有没有办法从 检索每个段落所在的页码XWPFParagraph 实例?
非常简单的问题。有人知道方法调用的组合吗?是否有任何手动方法来获取文档元素的起始行和结束行?也许通过计算偏移量(如果可以获得偏移值)。谢谢! 最佳答案 为了获取文档的行数,假设您已经实例化了一个 XW
我希望将从文档读取的所有现有正文元素写入表格单元格。这是代码。尽管 sysout 写入了元素文本,但这些段落并未添加到单元格中。 public static void insertElementsTo
我是一名优秀的程序员,十分优秀!