jxls-reader:参考中的示例不起作用

发布于 2024-10-19 02:25:57 字数 1489 浏览 4 评论 0原文

我需要从 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.javaEmployee.javaSimple 下载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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-10-26 02:25:57

我知道已经有一段时间了,但我做了一些调试搜索来回答这个问题,实际上我发现了一些东西。

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 to department.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 like chief = new Employee()

Now it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文