Apache POI Locking Header Rows

user1795755 picture user1795755 · Jul 29, 2013 · Viewed 41.6k times · Source

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 when the user is scrolling through the rows. My created spreadsheet will have 500 rows and it would be beneficial if the column’s names were always visible.

Answer

Sankumarsingh picture Sankumarsingh · Jul 30, 2013

In case you need to Freeze any particular row anywhere in the sheet you can use (Within org.apache.poi.ss.usermodel.Sheet) (Available in POI 3.7 as well)

Sheet.createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow)

In your case if you want to freeze just your first x rows then the int leftmostColumn, int topRow section will get removed and you can use just

Sheet.createFreezePane(int colSplit, int rowSplit)

for example

sheet1.createFreezePane(0, 5); // this will freeze first five rows