import org.apache.poi.POIXMLDocument; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFDocument;
HWPFDocument doc = new HWPFDocument(new FileInputStream(filePath)); int pages = doc.getSummaryInformation().getPageCount();// 总页数
程序运行到这里总是报以下错误:
java.lang.NoSuchMethodError: org.apache.poi.poifs.filesystem.POIFSFileSystem.getRoot()Lorg/apache/poi/poifs/filesystem/Director
解决如下:
//1、打开项目的properties->java build path->order and export,发现poi放到了最后,把poi的包移到最上面。(这个是网络上搜的,但没解决问题) //2、查看poi包是否冲突,比如poi包存在有多个版本,可在tomcat里搜索下poi相关的jar包。删除多余的jar包后问题解决
转载请注明原文地址: https://ju.6miu.com/read-20644.html