我需要获取使用 poi jar 创建的 docx 文件的行数。我使用了下面的代码
XWPFDocument doc1 = new XWPFDocument(POIXMLDocument.openPackage("LineCounter.docx"));
System.out.println("lines using method 2 --> " + doc1.getProperties().getExtendedProperties().getUnderlyingProperties().getLines());
System.out.println("word 2 --> " + doc1.getProperties().getExtendedProperties().getUnderlyingProperties().getWords());
仅当我将创建的 docx 的内容复制到新文件中时,上面的代码才有效。