如何获得最大无。填充在使用POI XLSX文件列? [英] How to get the max no. of columns filled in an XLSX file using POI?

查看:285
本文介绍了如何获得最大无。填充在使用POI XLSX文件列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们可以通过遍历所有行并调用 getLastCellNumber 每行对象获得列的最大数量。但这种方法需要在迭代的所有行我想避免,因为它会花费大量的时间与一百万行的文件(这是那种我期待文件读取)。

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).

在POI读取Excel文件,它存储在 DimensionsRecord 类。所以,如果我得到这个对象,我会得到我所需要的。这些对象可以从表类,这是一个内部类的POI来获得。我能提取我需要的XLS文件,但我已经打了XLSX文件的路障。

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.

POI是否保持XLSX还 DimensionsRecord 对象?如果是的话有任何人试图提取它?或者是有一些其他的由可以做到这一点?请帮忙!

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!

此外,我想问问,我的做法是否正确与否,也就是我使用POI的内部类(它让我的工作完成的),这是正确的或者我应该仅仅依靠公开的API(太耗时)。

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).

推荐答案

有一个关于XSSF表维对象了。尝试:

There's a dimension object on XSSF Sheets too. Try:

CTSheetDimension dimension = sheet.getCTWorksheet().getDimension();
String sheetDimensions = dimenson.getRef();

的一个问题是弹簧想到是我,如果它需要的尺寸(CTDimensions或DimensionsRecord)永远是正确的不知道...

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...

这篇关于如何获得最大无。填充在使用POI XLSX文件列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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