Issues resolving XSSFWorkbook - Java - POI .jar

2019-03-23 01:52发布

I'm trying to do work upgrading a Java application to handle .xlsx, using a newer POI library than our existing one. I'm having issues similar to those mentioned in the comments to the answer here: Apache POI, using both XSSF and HSSF

I'm pointing the new ss.usermodel, but it keeps telling me it can't resolve the XSSF workbook declaration:

Workbook xlsImport = new XSSFWorkbook();

I dug through some of their documentation and saw that XSSFWorkbook isn't a part of org.apache.poi.ss.usermodel. It's a part of org.apache.poi.xssf.usermodel.XSSFWorkbook. But there's no poi.xssf for me to import. Am I pointing to the wrong thing? I'm using POI 3.7 Thanks for any help you can provide.

4条回答
Evening l夕情丶
2楼-- · 2019-03-23 02:10

if you created maven project use below dependency in pom.xml file

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

otherwise import this in your java file

import org.apache.poi.ss.usermodel.Workbook;

查看更多
beautiful°
3楼-- · 2019-03-23 02:21

You need to include poi-ooxml jars. You can add it to pom.xml file

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.10-FINAL</version>
</dependency>
查看更多
Fickle 薄情
4楼-- · 2019-03-23 02:33

You need to include the poi-ooxml jars to get the XSSF library. The poi jar only has the HSSF libraries.

查看更多
爷的心禁止访问
5楼-- · 2019-03-23 02:37

First you need to include the proper jar files into your libraries, poi-ooxml-schemas-3.8-20120326.jar. You can find these at http://poi.apache.org/download.html. And you need to add the following link to your java file.

import org.apache.poi.xssf.usermodel.XSSFWorkbook;
查看更多
登录 后发表回答