我想找到一个列表段落(以 a. 开头),并将另一个列表项附加到该列表中(它取决于第一个列表元素的文本)。我尝试了许多创建新段落的方法,但我所取得的只是创建了新的列表元素,但是org.docx4j.wml.Text
对象被附加到段落中,新段落被附加了。新段落文本为空。如何创建新的列表元素并将其附加到正确的元素?
- 一个。列出元素 1 |测试| //|测试| 应附加到 b。
- 湾。//新项目被创建,但没有文本
- C。
//traverse through a document public List<Object> apply(Object obj) { if (obj instanceof org.docx4j.wml.P) { if (p.getPPr() != null) { if (p.getPPr().getPStyle() != null) { if ((p.getPPr().getPStyle().getVal().equals("Akapitzlist"))) { //there is a list paragraph ObjectFactory factory = Context.getWmlObjectFactory(); Object deepCopy = XmlUtils.deepCopy(obj); //Create the paragraph org.docx4j.wml.P para = factory.createP(); // Create the text element org.docx4j.wml.Text t = factory.createText(); t.setValue("|test|"); // Create the run org.docx4j.wml.R run = factory.createR(); run.getContent().add(t); para.getContent().add(run); //add new paragraph to the document ((org.docx4j.wml.P) obj).getContent().add(para); }...}