首页 文章

无法在Apache POI中导入XSSF

提问于
浏览
103

我正在引用Apache POI的3.7版本,当我这样做时,我收到“无法解决”的错误:

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

引用POI的其他import语句不会给我错误,例如:

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

有任何想法吗??

9 回答

  • 30

    你没有描述环境,无论如何,你应该下载apache poi库 . 如果您正在使用eclipse,请右键单击您的根项目,因此属性和java构建路径中添加外部jar并在项目中导入这些库:

    xmlbeans-2.6.0; poi-ooxml-schemas- ...; poi-ooxml- ...; poi ....

  • 0

    要使OOXML正常工作,您需要POI-OOXML jar,它与POI jar分开包装 .

    从以下位置下载POI-OOXML jar -

    http://repo1.maven.org/maven2/org/apache/poi/poi-ooxml/3.11/poi-ooxml-3.11.jar

    对于Maven2添加以下依赖项 -

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.11</version>
    </dependency>
    
  • 2

    OOXML文件格式的类(例如.xlsx的XSSF)位于不同的Jar文件中 . 您需要在项目中包含poi-ooxml jar以及它的依赖项

    您可以在POI网站here上获取所有组件及其依赖项的列表 .

    你可能想要做的是下载3.11 binary package,从中获取 poi-ooxml jar,以及 ooxml-lib 目录中的依赖项 . 将这些导入到您的项目中,您将被排序 .

    或者,如果您使用Maven,您可以see here获取您想要的类似物的列表:

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

    poi-ooxml maven依赖项将自动为您提供主要的POI jar和依赖项 . 如果您想使用非电子表格格式,您也需要依赖 poi-scratchpad 工件,详见POI components page

  • 7

    如果你使用Maven:

    poi => poi-ooxml in artifactId

    <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.12</version>
        </dependency>
    
  • 2

    问题:在导入显示eclipse错误的“org.apache.poi.xssf.usermodel.XSSFWorkbook”类时 .

    解决方案:使用此maven依赖项来解决此问题:

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

    -Hari Krishna Neela

  • 0

    1)从POI文件夹导入所有JARS 2)从ooxml文件夹导入所有JARS,POI文件夹的子目录3)从lib文件夹导入所有JARS,这是POI文件夹的子目录

    String fileName = "C:/File raw.xlsx";
    File file = new File(fileName);
    FileInputStream fileInputStream;
    Workbook workbook = null;
    Sheet sheet;
    Iterator<Row> rowIterator;
    try {
            fileInputStream = new FileInputStream(file);
            String fileExtension = fileName.substring(fileName.indexOf("."));
            System.out.println(fileExtension);
            if(fileExtension.equals(".xls")){
            workbook  = new HSSFWorkbook(new POIFSFileSystem(fileInputStream));
            }
            else if(fileExtension.equals(".xlsx")){
            workbook  = new XSSFWorkbook(fileInputStream);
            }
            else {
            System.out.println("Wrong File Type");
            } 
            FormulaEvaluator evaluator workbook.getCreationHelper().createFormulaEvaluator();
            sheet = workbook.getSheetAt(0);
            rowIterator = sheet.iterator();
            while(rowIterator.hasNext()){
            Row row = rowIterator.next();
            Iterator<Cell> cellIterator = row.cellIterator();
            while (cellIterator.hasNext()){
            Cell cell = cellIterator.next();
            //Check the cell type after evaluating formulae
           //If it is formula cell, it will be evaluated otherwise no change will happen
            switch (evaluator.evaluateInCell(cell).getCellType()){
            case Cell.CELL_TYPE_NUMERIC:
            System.out.print(cell.getNumericCellValue() + " ");
            break;
            case Cell.CELL_TYPE_STRING:
            System.out.print(cell.getStringCellValue() + " ");
            break;
            case Cell.CELL_TYPE_FORMULA:
            Not again
            break;
            case Cell.CELL_TYPE_BLANK:
            break;
            }
    }
     System.out.println("\n");
    }
    //System.out.println(sheet);
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e){
    e.printStackTrace();
    }​
    
  • 1

    我在app“build.gradle”中添加了以下内容

    implementation 'org.apache.poi:poi:4.0.0'
    implementation 'org.apache.poi:poi-ooxml:4.0.0'
    
  • 169

    我有同样的问题,所以我挖了poi-3.17.jar文件,里面没有xssf包 .

    然后我浏览了其他文件,发现了poi-ooxml-3.17.jar中的xssf int

    所以似乎解决方案是添加

    poi-ooxml-3.17.jar
    

    到你的项目,因为它似乎使它工作(至少对我来说)

  • 6

    我需要以下文件来实现:

    • poi-ooxml-schemas-3.14.20160307.jar

    • commons-codec-1.10.jar(这是你从apache获得的zip文件的"lib"文件夹中)

    • curvesapi-1.03.jar(在"ooxml-lib"文件夹中)

    • poi-3.14-20160307.jar

    • poi-ooxml-3.14-20160307.jar

    • xmlbeans-2.6.0.jar(在"ooxml-lib"文件夹中)

    (虽然老实说,我并不完全确定它们都是必要的......)这有点令人困惑,因为它们是以这种方式打包的 . 我需要手动将它们放在我自己的“lib”文件夹中,然后添加引用...

    Maven似乎总是下载超过我需要的内容,所以我总是手动放置libaries / dll和类似的东西 .

相关问题