POI HSSF读写Excel问题

hchzju hchzju 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
附件中是个Excel2003可以打开的文件(https://issues.apache.org/bugzilla/attachment.cgi?id=24273),但是用POI HSSF读取该文件不作任何操作然后保存为另一个文件,则新生成的文件用Excel2003打开会有以下错误:

POI版为3.2final,并且在最新的3.5dev以及3.8beta版都试过,都是不行

"Excel found unreadable content in "testUnreadablenew.xls". Do you want to recover the contents of this workbook?..."

然后实际恢复之后,文件中丢失了数据。下面是代码:


FileInputStream fis = null;
HSSFWorkbook wb = null;
try{
File f = new File("testUnreadable.xls");
if (f.exists()){
fis = new FileInputStream(f);
wb = new HSSFWorkbook(fis);
}
}catch (Throwable th){}
finally{
if (fis != null){
fis.close();
}
}
FileOutputStream stream = null;
try{
stream = new FileOutputStream("New.xls");
wb.write(stream);
}catch (Exception e){}
finally{
if (stream != null)
{
stream.close();
}
}


有谁碰到过类似问题么,谢谢~
...全文
评论 5
收藏 已收藏
分享
返回顶部
hchzju
Java 51,407 成员 86,127 内容