Apache POI:如何更改查看器中显示最多的行?

时间:2022-04-04 20:22:15

According documentation, Sheet.getTopRow() returns "The top row in the visible view when the sheet is first viewed after opening it in a viewer".

根据文档,Sheet.getTopRow()返回“当表单在查看器中打开后第一次查看时的可见视图中的第一行”。

How can I change this value?
It seems that Apache POI sets the last row as the top-most row by default - I'd like to display the first row instead.

如何改变这个值?在默认情况下,Apache POI似乎将最后一行设置为最顶层——我想显示第一行。

UPDATE:
I'm not sure whether this is important:
I create a sheet which contains 100 rows.
I'm using a freeze pane to always display the first 4 rows - these are indeed shown top-most. The first row which is shown after the freeze pane is row 101 (which is empty - so nothing is displayed).
I always need to scroll up to see any data.

I'd like to ask for a way that row 5 is shown instead after the file has been opened in a viewer.

更新:我不确定这是否重要:我创建了一个包含100行的表。我使用一个冻结窗格来显示前4行——它们确实是显示在最上面的。在冻结窗格之后显示的第一行是第101行(它是空的,所以不会显示任何内容)。我总是需要向上滚动才能看到任何数据。我想询问在查看器中打开文件后显示第5行的方法。

1 个解决方案

#1


1  

You need to do it with createFreezePane with no split set. (That's just how Excel encodes it)

你需要用createFreezePane来做,没有分割集。

If you want Excel row 10 (= POI row 9, POI is 0-based), then you'd need to do

如果您想要Excel第10行(= POI第9行,POI基于0),那么您需要这样做

sheet.createFreezePane(0, 0, 0, 10-1);

If you want to freeze the first 4 rows, then have Excel row 10 (=POI 9) shown at the top of the bottom section, then it'd be:

如果要冻结前4行,则在最下面部分的顶部显示Excel第10行(=POI 9),则为:

sheet.createFreezePane(0, 4, 0, 10-1);

(More details are in the createFreezePane JavaDocs)

(更多详情请见createFreezePane JavaDocs)

You should be able to check that it worked, by then fetching the top row

通过获取第一行,您应该能够检查它是否正常工作

#1


1  

You need to do it with createFreezePane with no split set. (That's just how Excel encodes it)

你需要用createFreezePane来做,没有分割集。

If you want Excel row 10 (= POI row 9, POI is 0-based), then you'd need to do

如果您想要Excel第10行(= POI第9行,POI基于0),那么您需要这样做

sheet.createFreezePane(0, 0, 0, 10-1);

If you want to freeze the first 4 rows, then have Excel row 10 (=POI 9) shown at the top of the bottom section, then it'd be:

如果要冻结前4行,则在最下面部分的顶部显示Excel第10行(=POI 9),则为:

sheet.createFreezePane(0, 4, 0, 10-1);

(More details are in the createFreezePane JavaDocs)

(更多详情请见createFreezePane JavaDocs)

You should be able to check that it worked, by then fetching the top row

通过获取第一行,您应该能够检查它是否正常工作