通过Apache POI读取XLSM工作簿时异常 [英] Exception when reading XLSM workbook via Apache POI

查看:1526
本文介绍了通过Apache POI读取XLSM工作簿时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读 .XLSM 文件使用Apache POI库(3.8 beta5的):

I'm trying to read .xlsm file using Apache POI library (3.8-beta5):

Workbook wb = null;
try {
    wb =  WorkbookFactory.create(isXLSFile);
} catch (IOException e) {
...

没有什么复杂的。当正在读一般的文件很好,一个文档抛出异常:

nothing complicated. While generally documents are being read well, one document throws an exception:

Caused by: java.lang.IllegalStateException: A sheet hyperlink must either have a location, or a relationship. Found:
<xml-fragment ref="H13" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac"/>
    at org.apache.poi.xssf.usermodel.XSSFHyperlink.<init>(XSSFHyperlink.java:72)
    at org.apache.poi.xssf.usermodel.XSSFSheet.initHyperlinks(XSSFSheet.java:250)
    at org.apache.poi.xssf.usermodel.XSSFSheet.read(XSSFSheet.java:203)
    at org.apache.poi.xssf.usermodel.XSSFSheet.onDocumentRead(XSSFSheet.java:175)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.onDocumentRead(XSSFWorkbook.java:260)
    at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:159)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:174)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:67)

有趣的是,如果我打开的LibreOffice文件(没有的MS Office我的机器上),并重新保存(保持格式),然后文档是只读的罚款。据我所知,这个问题牵扯到与文档结构的有效性 - 所以这是库code数据问题,而不是错误(或者是不是?)。但也许有共进晚餐preSS这种错误的方式?

It's interesting that if I open file in LibreOffice (no MS Office on my machine) and re-save it (keeping the format) then document is read fine. As I understand this problem has something to do with validity of document structure - so this is data problem and not error in library code (or isn't it?). But maybe there is a way to suppress such errors?

[更新] 在注释中接受的答案中提到的修复程序集成在3.8版本的Apache POI的3月26日发布的2012年。

[UPDATE] The fix mentioned in comments to accepted answer was integrated in 3.8 version of Apache POI released on March 26th 2012.

推荐答案

我刚刚得到一个像这样的文件来自于谷歌瑞风bug报告的用户。我的结论是,这是一个Apache POI的错误,他们正在被抱怨是没有用的引用过于严格。此外,投掷,而不是一个声明(检查)异常一个RuntimeException是一种不礼貌的。我提起这个错误报告: https://issues.apache.org/bugzilla /show_bug.cgi?id=52716

I just got a file like this from a user in a Google Refine bug report. My conclusion is that it's an Apache POI bug and they're being overly strict by complaining about a reference which isn't used. Additionally, throwing a RuntimeException instead of a declared (checked) exception is kind of rude. I've filed this bug report: https://issues.apache.org/bugzilla/show_bug.cgi?id=52716

这篇关于通过Apache POI读取XLSM工作簿时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆