为什么单元格值即使有内容也会返回为空字符串?
我编写了一个 Java 方法,使用 POI HSSF API 将 Excel 文件转换为我的数据结构。
该代码在一段时间内运行良好。但现在突然出现了问题。我怀疑这可能是因为最近我们在所有客户端计算机上安装了 Office 2007,之前我们安装了 Office 2003。
我遇到的问题是: 在 XLS 文件中,我有一列单元格,其中由用户填充了序列号。当 Java 应用程序获取单元格时,它的单元格类型为 STRING。当我询问单元格的字符串值时,我得到一个空字符串。
该文件最初由应用程序创建,然后用户用数据填充该文件并将其加载回应用程序中。所以我不认为文件格式有问题,因为它是由相同版本的 API 创建的。
可能是什么问题?
编辑:
澄清:我们将 Office 安装升级到 2007,但应用程序仍然使用 HSSF 和 XLS 格式。只有用户可以使用 Office 2007 打开和编辑文件。这是一个问题吗?
I wrote a Java method that uses POI HSSF API to convert an Excel file to my data structure.
The code worked just fine for a while. But now there are suddenly problems. I suspect it might be because recently we installed Office 2007 on all the client computers, previously we had Office 2003.
The problem I ran into is: Inside the XLS file I have a column of cells that is filled with serial-numbers by the user. When the Java application gets the cell, it has a cell type STRING. And when I ask for the string value of the cell I get an empty string.
The file is originally created by the application, then the users fill it with data and load it back into the aplication. So I don't think the file format is wrong, since it's created by the same version of the API.
What could be the problem?
EDIT:
Clarification: We upgraded Office installation to 2007, but the application still uses HSSF and XLS format. Only the users open and edit the files with Office 2007. Is that a problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否检查过当用户输入值时 Excel 是否自动将单元格类型切换为 NUMERIC?
Excel 有一个恼人的功能,可以“智能地猜测”用户输入的值类型,这通常会导致 POI 出现问题。
Have you checked if Excel automatically switched the cell type to NUMERIC when the user entered the value?
Excel has this annoying feature to "intelligently guess" what kind of value the user enters which then often causes a problem in POI.
HSSF 是 POI 项目对 Excel '97(-2007) 文件格式的纯 Java 实现。 XSSF 是 POI 项目对 Excel 2007 OOXML (.xlsx) 文件格式的纯 Java 实现。
进一步阅读
http://poi.apache.org/spreadsheet/index.html
HSSF is the POI Project's pure Java implementation of the Excel '97(-2007) file format. XSSF is the POI Project's pure Java implementation of the Excel 2007 OOXML (.xlsx) file format.
read furthur
http://poi.apache.org/spreadsheet/index.html