此外,已删除的文本运行的 CTR 对象中具有 rsidDel 属性,而从未删除的运行中获取该属性将得到 null .>此外,文本运行的 CTR 中的 getDelTextList 将返回未删除运行的空列表,但将返回已删除运行的填充列表.示例,用于检测来自 WordExample.docx 的已删除运行. import java.io.FileInputStream;导入org.apache.poi.xwpf.usermodel.*;公共类WordReadDeletedRuns {公共静态void main(String [] args)引发异常{字符串inFilePath ="./WordExample.docx";XWPFDocument document =新的XWPFDocument(new FileInputStream(inFilePath));对于(IBodyElement bodyElement:document.getBodyElements()){如果(XWPFParagraph的bodyElement实例){XWPFParagraph段落=(XWPFParagraph)bodyElement;对于(IRunElement runElement:paragraph.getIRuns()){如果(XWPFRun的runElement instance){XWPFRun run =(XWPFRun)runElement;System.out.println(找到文字运行:" + run.text());System.out.println(run.getText(0));//对于已删除的运行,为nullSystem.out.println(run.getCTR().getRsidDel());//对于未删除的运行,为null;对于已删除的运行,为byte []System.out.println(run.getCTR().getDelTextList().size());//空列表(未删除运行),填充列表(已删除运行)}}}}document.close();}} I am using apache-poi to read word files, and it is working.I read the document text using a list of XWPFRun instances, and that is working fine.But if track change is enabled for the document, I also get XWPFRun instances for text which have been deleted, if the delete have not been accepted. And I would like not to include this text.So is there a way to detect track change status for a XWPDRun node, or even better a way to parse the document as if all track changes were accepted? 解决方案 This is not yet supported by XWPFRun. But we could determine whether there are text runs marked as deleted.Normal text run's XML looks like:<w:r> <w:t>Lorem</w:t></w:r>Deleted text runs look like:<w:del w:id="0" w:author="axel" w:date="2020-04-23T18:57:00Z"> <w:r w:rsidDel="00C63AEB"> <w:delText>ipsum</w:delText> </w:r></w:del>So deleted runs are within a del element. But this is tricky to get.But while normal text run's text is in a t element, it is in a delText element for deleted text runs. So XWPFRun.getText(0) will return null for deleted text runs, because this only traverses the t elements of the run. XWPFRun.text() or XWPFRun.toString() will return the text of the deleted runs too, because those methods traverses all elements which contain text in the run.Furthermore, deleted text runs have rsidDel attribute in it's CTR object while getting that attribute from not deleted runs will get null.And furthermore, getDelTextList from CTR of a text run will return a empty list for not deleted runs, but will return a filled list for deleted runs.Example to detect deleted runs from a WordExample.docx.import java.io.FileInputStream;import org.apache.poi.xwpf.usermodel.*;public class WordReadDeletedRuns { public static void main(String[] args) throws Exception { String inFilePath = "./WordExample.docx"; XWPFDocument document = new XWPFDocument(new FileInputStream(inFilePath)); for (IBodyElement bodyElement : document.getBodyElements()) { if (bodyElement instanceof XWPFParagraph) { XWPFParagraph paragraph = (XWPFParagraph)bodyElement; for (IRunElement runElement : paragraph.getIRuns()) { if (runElement instanceof XWPFRun) { XWPFRun run = (XWPFRun)runElement; System.out.println("Text run found: " + run.text()); System.out.println(run.getText(0)); // null for deleted runs System.out.println(run.getCTR().getRsidDel()); // null for not deleted runs, byte[] for deleted runs System.out.println(run.getCTR().getDelTextList().size()); // empty list for not deleted runs, filled list for deleted runs } } } } document.close(); }} 这篇关于如何检测到曲目更改请求已删除了文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-07 01:15