Cannot import XSSF in Apache POI

后端 未结 11 604
无人及你
无人及你 2020-11-29 01:59

I am referencing the version 3.7 of the Apache POI and I am getting a \"cannot be resolved\" error when I do:

import org.apache.poi.xssf.usermodel.XSSFWorkbo         


        
相关标签:
11条回答
  • 1) imported all the JARS from POI folder 2) Imported all the JARS from ooxml folder which a subdirectory of POI folder 3) Imported all the JARS from lib folder which is a subdirectory of POI folder

    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();
    }​
    
    0 讨论(0)
  • 2020-11-29 02:36

    I added below contents in app "build.gradle"

    implementation 'org.apache.poi:poi:4.0.0'
    implementation 'org.apache.poi:poi-ooxml:4.0.0'
    
    0 讨论(0)
  • 2020-11-29 02:37

    Problem: While importing the " org.apache.poi.xssf.usermodel.XSSFWorkbook"class showing an error in eclipse.

    Solution: Use This maven dependency to resolve this problem:

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

    -Hari Krishna Neela

    0 讨论(0)
  • 2020-11-29 02:39

    After trying multiple things,what really worked was: 1. downloading "poi" and "poi-ooxml" manually 2.Adding these d/w jars into "Maven Dependencies"

    0 讨论(0)
  • 2020-11-29 02:43

    I had the same problem, so I dug through the poi-3.17.jar file and there was no xssf package inside.

    I then went through the other files and found xssf int the poi-ooxml-3.17.jar

    So it seems the solutions is to add

    poi-ooxml-3.17.jar
    

    to your project, as that seems to make it work (for me at least)

    0 讨论(0)
  • 2020-11-29 02:53

    I needed the following files for my implementation:

    • poi-ooxml-schemas-3.14.20160307.jar
    • commons-codec-1.10.jar (this was in "lib" folder of the zip file you get from apache)
    • curvesapi-1.03.jar (in "ooxml-lib" folder)
    • poi-3.14-20160307.jar
    • poi-ooxml-3.14-20160307.jar
    • xmlbeans-2.6.0.jar (in "ooxml-lib" folder)

    (though honestly, I'm not completely sure they are all necessary...) It's a little confusing because they are packaged that way. I needed to place them manually in my own "lib" folder and then add the references...

    Maven always seems to download more than I need, so I always place libaries/dlls and things like that manually.

    0 讨论(0)
提交回复
热议问题