小编Pur*_*ima的帖子

使用POI读取.xlsx文件时出现错误"Zip文件已关闭"

public Sheet readExcel() throws Exception{
    //File fi=new File(new File(System.getProperty("user.dir"))+"\\src\\testdata2.xls");
    File fi=new File("C:\\Users\\admin\\workspace\\HMS\\src\\testdata\\testdata1.xlsx");

    Workbook wb = new XSSFWorkbook(fi);
    Sheet  Sheet = wb.getSheetAt(0);

    int rowCount = Sheet.getLastRowNum()-Sheet.getFirstRowNum();

    for (int i = 1; i < rowCount+1; i++) {
        Row row = Sheet.getRow(i);

        if(row.getCell(0).toString().length()==0){

            System.out.println(row.getCell(1).toString()+"----"+ row.getCell(2).toString()+"----"+

            row.getCell(3).toString()+"----"+ row.getCell(4).toString());
        }
    }    
    return Sheet;   
}
Run Code Online (Sandbox Code Playgroud)

通过运行上面的代码我得到这样的错误........

线程"main"中的异常java.lang.IllegalStateException:Zip文件在org.apache.poi.openxml4j.opc.ZipPackage的org.apache.poi.openxml4j.util.ZipFileZipEntrySource.getEntries(ZipFileZipEntrySource.java:45)处关闭. orP.apache.poi.opei.open上的org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:684)中的getPartsImpl(ZipPackage.java:186)(OPCPackage.java:254)在Org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:201)org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:294)at ExcelReader.readExcel(ExcelReader.java: 16)在ExcelReader.main(ExcelReader.java:30)

任何人都可以帮我找出究竟是什么问题.

我用Google搜索但无法获得解决方案!

java excel zip apache-poi

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

apache-poi ×1

excel ×1

java ×1

zip ×1