简体   繁体   中英

How to read Excel file with *.xlsx Extension?

I am reading excel file* (2000000 row with 6 column) * with xlsx extension. for reading it using Java Excel API but it throw exception

jxl.read.biff.BiffException: Unable to recognize OLE stream

when try same file with xls extension it read perfectly but it reading only 65536 Row data only remaining rest of row unread.please help me how i am able to read remaining row with xlsx extension.

Thanks

For reading xlsx file we use following jars,

1.dom4j-1.6.1.jar 2.org-apache-commons-codec.jar 3.poi-3.7.jar 4.poi-ooxml-3.5-FINAL.jar 5.poi-ooxml-schemas-3.11-beta2.jar 6.stax-api-1.0.1.jar 7.xmlbeans-2.6.0.jar

This is function through which you can read the the xlsx file.

public static void readXLSX(String path) {
    File file = new File(path);
    String value = "";
    XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(path));
    XSSFSheet sheet = wb.getSheetAt(0);

    Row row;
    Cell cell;

    Iterator<Row> rowIterator = sheet.iterator();

    while (rowIterator.hasNext()) {
        row = rowIterator.next();
        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()) {
                    cell = cellIterator.next();
                    switch (cell.getCellType()) {
                        case Cell.CELL_TYPE_BOOLEAN:
                            value = "" + cell.getBooleanCellValue();
                            break;
                        case Cell.CELL_TYPE_NUMERIC:
                            value = "" + cell.getNumericCellValue();
                            break;
                        case Cell.CELL_TYPE_STRING:
                            value = "" + cell.getStringCellValue();
                            break;
                        case Cell.CELL_TYPE_BLANK:
                            value = " ";
                            break;
                        default:
                            break;
                    }
                    System.out.println("Value: "+value);
    }

}

The problem is that in Office '07 Microsoft changed its document format to something which is more or less a zip file that contains a large amount of XML. The Java Excel API relies on the old file format. To read something from Office '07, use Apache POI .

  1. Don't read Microsoft formats. If you want an excel document read a CSV, comma separated list.
  2. Your library doesn't seem to support xlsx
  3. Take a look here Choosing an excel java api

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM