How to read excel using jexcel?

Simran picture Simran · Aug 5, 2010 · Viewed 10.4k times · Source

i am trying to read an Excel file using Java code however i am getting following error :

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

when i searched on net i found jExcel supports only upto excel 2003, and this error comes when excel is made in 2007 bt i have saved my excel in 97-2003 format only and i am still getting this problem

Answer

urmalp picture urmalp · Aug 5, 2010

JExcel API does not support excel 2007,you can use Apache POI HSSF/XSSF

here is sample code for Reading and Rewriting Workbooks from the site

InputStream inp = new FileInputStream("workbook.xls");
//InputStream inp = new FileInputStream("workbook.xlsx");

Workbook wb = WorkbookFactory.create(inp);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
Cell cell = row.getCell(3);
if (cell == null)
    cell = row.createCell(3);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("a test");

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
wb.write(fileOut);
fileOut.close();