Apache POI Locking Header Rows

后端 未结 3 1996
無奈伤痛
無奈伤痛 2021-01-31 13:26

Is anyone out there familiar with a way to lock a row in a spreadsheet created with Apache POI 3.7? By locking I mean that I want the title row for the columns to remain visible

3条回答
  •  执念已碎
    2021-01-31 13:57

    You can not freeze a middle row without getting the rows above it also freezed.

    Say you have 100 rows and your header row is at line 50. You might expect that only row 50 gets locked so that when scrolling from line 1-49, everything is scrolled up and when it reaches line 50, the 50th row scrolls to the top and stays there when lines 51-100 is scrolled.

    But, there is a workaround. What you can do is, group the rows and then freeze them.

    First, group the rows from 1-49 and then freeze panes from 1-50. Now the user can minimize the group and then work with the table with the table header locked and at the top.

    sheet.groupRow(0, 49);
    sheet.createFreezePane(0, 50);
    

    There is a small catch though. MS Excel won't let you expand/collapse a group if the sheet is protected. For this you need to write a Macro.

提交回复
热议问题