jxls-reader:参考中的示例不起作用
我需要从 Java 读取 XLS 文件。为此,我开始评估 jXLS 框架。不幸的是,我在尝试在 XLS 阅读器参考 上运行示例时仍然遇到以下异常页面:
Exception in thread "main" net.sf.jxls.reader.XLSDataReadException: Can't read cell A4 on Sheet1 spreadsheet
at net.sf.jxls.reader.SimpleBlockReaderImpl.read(SimpleBlockReaderImpl.java:61)
at net.sf.jxls.reader.XLSSheetReaderImpl.read(XLSSheetReaderImpl.java:25)
at net.sf.jxls.reader.XLSReaderImpl.readSheet(XLSReaderImpl.java:45)
at net.sf.jxls.reader.XLSReaderImpl.read(XLSReaderImpl.java:31)
at com.oracle.sk.jxls.App.go(App.java:46)
at com.oracle.sk.jxls.App.main(App.java:19)
我对原始版本所做的更改是:
- 将 Department.java 和 Employee.java 移动到主类所在的同一个包中(换句话说,在 App.java 旁边)
- 添加空的无参数构造函数以
- 更改 varType (完整) Employee 和 Department 的类名)相应地出现在 Departments.xml 中。
Departments.xml 和 Departmentdata.xls 均直接取自 XLS 阅读器参考页面。 Department.java 和 Employee.java 从 Simple 下载beans 页面(也在 jXLS 站点上)。如果需要,我可以提供我完整的 Maven 项目。
请问,有人知道为什么它不起作用吗?
先感谢您。
I need to read XLS files from Java. For that purpose I start evaluating jXLS framework. Unfortunately, I'm still getting following exception while trying to run example on their XLS reader reference page:
Exception in thread "main" net.sf.jxls.reader.XLSDataReadException: Can't read cell A4 on Sheet1 spreadsheet
at net.sf.jxls.reader.SimpleBlockReaderImpl.read(SimpleBlockReaderImpl.java:61)
at net.sf.jxls.reader.XLSSheetReaderImpl.read(XLSSheetReaderImpl.java:25)
at net.sf.jxls.reader.XLSReaderImpl.readSheet(XLSReaderImpl.java:45)
at net.sf.jxls.reader.XLSReaderImpl.read(XLSReaderImpl.java:31)
at com.oracle.sk.jxls.App.go(App.java:46)
at com.oracle.sk.jxls.App.main(App.java:19)
Changes I've made against original are:
- moved Department.java and Employee.java into the same package where main class is (in other words next to App.java)
- add empty no-args constructor to both
- change the varType (full class names for Employee and Department) everywhere in departments.xml accordingly
Both departments.xml and departmentdata.xls are taken directly from the XLS reader reference page. Department.java and Employee.java are downloaded from Simple beans page (on jXLS site too). If necessary, I can provide my complete Maven project.
Please, does anyone have a clue, why it is not working?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道已经有一段时间了,但我做了一些调试搜索来回答这个问题,实际上我发现了一些东西。
从
departments.xml
中,您可以看到 A4 单元格映射到department.chief.name
,但是当它初始化 Department 对象时,chief 属性为 null,因此在Department 无参数构造函数,您应该执行类似chief = new Employee()
的操作,现在它应该可以工作了。
I know it has been a while, but I did some debugging searching to answer this problem, an actually I found out something.
From the
departments.xml
you see that the A4 cell is mapped todepartment.chief.name
, but when it initializes your Department object, the chief property is null, so in the Department no-args constructor you should do something likechief = new Employee()
Now it should work.