How to process old excel .xls files using POI?

风格不统一 提交于 2019-11-29 09:07:22

For old Excel format files, you have the following alternatives:

  1. HSSF, the POI implementation of the Excel '97(-2007) file format.
    • If you just want to extract the textual content, then you can use OldExcelExtractor which will pull only the text and numbers from the file.
    • If you need the values from a specific cells, then you'll need to take an approach a bit like OldExcelExtractor, process the file at the record level, and check for the co-ordinates on OldStringRecord, NumberRecord, OldFormulaRecord and friends.
  2. Like you already mentioned, JXL can handle some cases too.
  3. Use a JDBC/ODBC driver. It is not as flexible as HSSF but for some old formats it is the only way to extract the information.

as per my knowledge you can use this code to read excel files of the .xls format

FileInputStream in=new FileInputStream(new File("filename.xls"));
Wookbook wb=new HSSFWorkbook(in);

to read the new excel versions(2007 and up):

 FileInputStream in=new FileInputStream(new File("filename.xls"));
    Wookbook wb=new XSSFWorkbook(in);

external jar files that you will need:

 1. poi-3.9 
 2. dom4j-1.6.1
 3. XMLbeams-2.5.0

if you're work only requires you to work with .xls then only poi-3.0 will suffice. You need the other jars to work witht the new versions of excel.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!