实现XSSF示例时出错

时间:2015-03-19 12:55:55

标签: excel apache-poi xlsx

我想用java阅读大型Excel文件(.xlsx)。 Apache有一个例子来说明如何here。 所以我只是复制了整个类,添加了我的.xlsx文件的路径并尝试执行它但是我收到了这个错误:

Error:(96, 69) java: cannot access org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst
class file for org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst not found

方法endElement()中的此行触发了此错误:

lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();

我对maven使用这种依赖:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.9</version>
</dependency>

如何解决此错误?

1 个答案:

答案 0 :(得分:0)

在Gagravarr的帮助下,我能够解决这个问题。我只需要将以下依赖项添加到maven:

    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.9</version>
    </dependency>
    <dependency>
        <groupId>stax</groupId>
        <artifactId>stax-api</artifactId>
        <version>1.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>2.6.0</version>
    </dependency>
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>