Apache的POI HSSF XLS读数误差 [英] Apache POI HSSF XLS reading error
问题描述
使用以下$ C $℃,同时在一个.xls文件,其中s是文件目录读取
Using the following code while reading in a .xls file, where s is the file directory:
InputStream input = new FileInputStream(s);
Workbook wbs = new HSSFWorkbook(input);
我收到以下错误信息:
I get the following error message:
Exception in thread "main" java.io.IOException: Invalid header signature; read 0x0010000000060809, expected 0xE11AB1A1E011CFD0
我需要一个程序,可以在任何XLSX或XLS阅读,使用完全相同的code只是调整XSSF它在在XLSX文件中的所有阅读没有问题的。
I need a program that is able to read in either XLSX or XLS, and using the exact same code just adjusted for XSSF it has no problem at all reading in the XLSX file.
推荐答案
如果该文件是XLSX格式而不是XLS你可能会得到这个错误。我会尝试使用通用Workbook对象(也称为SS的usermodel)
If the file is in xlsx format instead of xls you might get this error. I would try using the generic Workbook object (Also called the SS Usermodel)
查看工作簿接口并 WorkbookFactory对象。工厂应该能够为你创建一个通用的工作簿出来要么XLSX或XLS的。
Check out the Workbook interface and the WorkbookFactory object. The factory should be able to create a generic Workbook for you out of either xlsx or xls.
我觉得我有这个一个很好的教程,但我似乎无法找到它。我会继续寻找,虽然
I thought I had a good tutorial on this, but I can't seem to find it. I'll keep looking though.
修改
我发现从Apache的这一点微小的片段网站关于阅读和使用SS的usermodel重写。
I found this little tiny snippet from Apache's site about reading and rewriting using the SS Usermodel.
我希望这有助于!
这篇关于Apache的POI HSSF XLS读数误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!