开发者

How to read Excel file with *.xlsx Extension?

开发者 https://www.devze.com 2023-03-13 11:01 出处:网络
I am reading excel file*(2000000 row with 6 column)* with xlsx extension. for reading it us开发者_运维百科ing Java Excel API but it throw exception

I am reading excel file*(2000000 row with 6 column)* with xlsx extension. for reading it us开发者_运维百科ing 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


try use Apache POI http://poi.apache.org/spreadsheet/index.html


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号