需要打开2003格式的XLS和2007+格式的XLSX。 有像
这样的代码Workbook workbook = WorkbookFactory.create( inputStream );
pom.xml
包含:
但是用SAX获得例外:
Could not initialize a SAX Parser. Please add a SAX parser to your classpath along with preferably jaxp.jar
并且像
SAXReader xmlReader = new SAXReader(); //using dom4j library
xmlReader.read(file);
我发现在我的类路径中有两个org.xml.sax.XMLReader类。一个在java 1.7 rt.jar中,另一个在xml-apis:xml-apis
工件中。当dom4j尝试创建XMLReader时,它会尝试将其从xml-apis:xml-apis
转换为XMLReader,而不是从rt.jar转换。然后失败了。
嗯,我想并从我的pom.xml中的所有隐式依赖项中排除了xml-apis:xml-apis。 然后 - hallelujah - SAXReader工作!
但是另一个例外失败了: 在创建Workbook时,poi-ooxml转到ThemesTable.java:44并执行
theme = ThemeDocument.Factory.parse(part.getInputStream());
java.lang.NoClassDefFoundError抛出消息"无法初始化类org.apache.xmlbeans.XmlBeans"
但是org.apache.xmlbeans:xmlbeans:jar:2.3.0在我的结果jar中! 示例代码失败:
XmlBeans.compilePath( "" );
但如果你认为 - 如果pom.xml中包含xml-apis:xml-apis
,它会起作用吗?
帮助,伙计们,如何为ooxml驯服apache.poi?