简体   繁体   English

读取 .xls 和 .xlsx 格式的 excel 文件时获取 jxl.read.biff.BiffException 异常

[英]Getting jxl.read.biff.BiffException exception while reading .xls and .xlsx format excel files

Using below code, i'm getting jxl.read.biff.BiffException: Unable to recognize OLE stream .使用下面的代码,我得到jxl.read.biff.BiffException: Unable to recognize OLE stream I want to use .xls and .xlsx format files.我想使用 .xls 和 .xlsx 格式的文件。 how to solve this?如何解决这个问题?

Service.java服务.java

@Override
public boolean facultyDump(String path, HttpSession httpSession) {
    Session session=sessionFactory.openSession();
    session.beginTransaction();
    File inputWorkbook = new File(path);
    Workbook w;
    try{
        w = Workbook.getWorkbook(inputWorkbook);
        Sheet sheet = w.getSheet(0);
        for (int i = 1; i < sheet.getRows(); i++) {
            for (int j = 0; j < sheet.getColumns(); j++) {
                Cell cell = sheet.getCell(j, i);
                if (j == 0) {
                    String name= cell.getContents().trim();
                } 
            }
        }
    }catch(Exception ex){
        ex.printStackTrace();
    }finally{
        session.close();sessionFactory.close();
    }
    return false;
}

Exception at Console:控制台异常:

jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:221)
at jxl.Workbook.getWorkbook(Workbook.java:198)
at com.slv.daoimpl.RegistrationDaoImpl.facultyDump(RegistrationDaoImpl.java:2845)
at com.slv.controller.SuperAdminController.facultyDumpExcel(SuperAdminController.java:327)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
@Override
public boolean facultyDump(String path, HttpSession httpSession) {
    Session session=sessionFactory.openSession();
    session.beginTransaction();
    File inputWorkbook = new File(path);
    try{
        FileInputStream fis = new FileInputStream(inputWorkbook);
        org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(fis);
        org.apache.poi.ss.usermodel.Sheet mySheet = workbook.getSheetAt(0);
         Iterator<Row> rowIterator = mySheet.iterator();
         while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                Iterator<Cell> cellIterator = row.cellIterator();
                while (cellIterator.hasNext()) {
                    Cell cell = cellIterator.next();
                    switch (cell.getCellType()) {
                    case Cell.CELL_TYPE_STRING:
                        System.out.print(cell.getStringCellValue() + "\t");
                        break;
                    case Cell.CELL_TYPE_NUMERIC:
                        System.out.print(cell.getNumericCellValue()+ "\t") ;
                        break;
                    case Cell.CELL_TYPE_BOOLEAN:
                        System.out.print(cell.getBooleanCellValue() + "\t");
                        break;
                    default :
                    }
                }
            }   
    }catch(Exception ex){
        ex.printStackTrace();
    }finally{
        session.close();sessionFactory.close();
    }
    return false;
}
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFSheet;

try{
    FileInputStream file = new FileInputStream(new File("C:\\test.xlsx"));

    //Get the workbook instance for XLS file 
    XSSFWorkbook workbook = new XSSFWorkbook (file);

    //Get first sheet from the workbook
    XSSFSheet sheet = workbook.getSheetAt(0);

    //Get iterator to all the rows in current sheet
    Iterator<Row> rowIterator = sheet.iterator();

    //Get iterator to all cells of current row
    Iterator<Cell> cellIterator = row.cellIterator();

     while(cellIterator.hasNext()) {
            Cell cell = cellIterator.next();    
            switch(cell.getCellType()) {
                case Cell.CELL_TYPE_BOOLEAN:
                    System.out.print(cell.getBooleanCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "\t\t");
                    break;
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getStringCellValue() + "\t\t");
                    break;
            }
       }
    file.close();
}catch(Exception e){
    e.printStackTrace();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想在现有的Excel工作表中添加单元格,但出现此错误jxl.read.biff.BiffException: - I want to add cell in existing excel sheet but I am getting this error jxl.read.biff.BiffException: jxl.read.biff.BiffException:无法识别OLE流 - jxl.read.biff.BiffException: Unable to recognize OLE stream jxl.read.biff.BiffException:找不到输入文件 - jxl.read.biff.BiffException: The input file was not found 如何解决JXL错误:jxl.read.biff.BiffException:无法识别OLE流 - how to solve JXL error : jxl.read.biff.BiffException: Unable to recognize OLE stream Sap 门户 NetWeaver 7.4:jxl.read.biff.BiffException:无法识别 OLE 流 - Sap Portal NetWeaver 7.4: jxl.read.biff.BiffException: Unable to recognize OLE stream javax.el.E​​LException:java.lang.NoClassDefFoundError:jxl / read / biff / BiffException - javax.el.ELException: java.lang.NoClassDefFoundError: jxl/read/biff/BiffException 读取大型XLS和XLSX Excel格式 - Reading large XLS and XLSX excel format Getting Out of memory when reading large excel files (.xls) using Workbook method of apache poi jxl-2.6.jar - Getting Out of memory when reading large excel files (.xls) using Workbook method of apache poi jxl-2.6.jar 如何在使用jxl读取excel文件时检查单元格是否为空 - How to check if a cell is blank while using jxl to read excel files 读取Big XLS和XLSX文件 - Reading Big XLS and XLSX files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM