如何获得最大数量使用 POI 填充 XLSX 文件中的列数?
我知道我们可以通过迭代所有行并在每个行对象上调用 getLastCellNumber 来获得最大列数。但是这种方法需要迭代我想要避免的所有行,因为它需要对于具有一百万行的文件(这是我期望读取的文件类型)需要花费很多时间。
当 POI 读取 Excel 文件时,它将工作表尺寸(第一行号、最后一行号、第一列号、最后列号)存储在 DimensionsRecord 类的对象中。因此,如果我得到这个对象,我就会得到我需要的东西。这些对象可以从POI的内部类Sheet类中获取。我能够提取 XLS 文件所需的内容,但在获取 XLSX 文件时遇到了障碍。
POI 是否也维护 XLSX 的 DimensionsRecord 对象?如果是,有人尝试提取它吗?或者还有其他方法可以做到这一点吗?请帮忙!
我还想问,我的方法是否正确,即我使用 POI 的内部类(它正在完成我的工作),这是正确的还是我应该仅依赖公开的 API(太耗时)。
I know we can get the max number of columns by iterating over all the rows and calling getLastCellNumber
on each row object.. but this approach requires iterating over all the rows which I want to avoid since it will take lot of time for files with a million rows(that’s the kind of files I am expecting to be read).
When POI reads a excel file, it stores the sheet dimensions (first row number, last row number , first col number, last col number) in an object of the DimensionsRecord
class. So if I get this object I will get what I need. These objects can be obtained from the Sheet class which is an inner class of POI. I was able to extract what I need for XLS files, but I have hit a roadblock for XLSX files.
Does POI maintain DimensionsRecord
object for XLSX also?, if yes has anybody tried to extract it? Or Is there some other by which this can be done?? please help!
Also I wanted to ask, whether my approach is correct or not, i.e I am using the inner classes of POI (it is getting my work done), is this correct or should I solely rely on exposed APIs (too time consuming).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XSSF Sheets 上也有一个维度对象。尝试:
我想到的一个问题是我不确定尺寸(CTDimensions 或 DimensionsRecord)是否需要始终正确......
There's a dimension object on XSSF Sheets too. Try:
The one issue that springs to mind is I'm not sure if it's required for the dimension (CTDimensions or DimensionsRecord) to always be correct...