DsExcel Java enables users to freeze panes in a worksheet. This feature allows users to keep some specific rows or columns visible while scrolling through the rest of the sheet. In a large worksheet with a lot of data, this functionality is helpful in enhancing readability and data manipulation of bulk information that spans across a number of rows or columns.
Additionally, it allows to set the custom color of lines of frozen panes. However, these colors are only visible while interacting with SpreadJS by doing JSON I/O and are not visible in Excel or PDF.
You can freeze panes in a worksheet using the freezePanes method of the IWorksheet interface. This method freezes the split panes based on the specified row index and column index parameters.
In order to represent the row of freeze position and the column of freeze position, you can use the getFreezeRow and getFreezeColumn methods respectively.
To see how panes in a worksheet can be freezed, refer to the following example code.
Java |
Copy Code |
---|---|
// Adding worksheets to the workbook IWorksheet worksheet = workbook.getWorksheets().get(0); worksheet.freezePanes(worksheet.getRange("A5").getRow(), worksheet.getRange("A5").getColumn()); IWorksheet worksheet2 = workbook.getWorksheets().add(); // Freeze Panes worksheet2.freezePanes(worksheet.getRange("B10").getRow(), worksheet.getRange("B10").getColumn()); |
You can also set custom color of lines of frozen panes using the setFrozenLineColor method of IWorksheet interface.
Refer to the following example code to set blue color for lines of frozen panes in a worksheet.
Java |
Copy Code |
---|---|
// Use sheet index to get worksheet IWorksheet worksheet = workbook.getWorksheets().get(0); // Freeze pane worksheet.freezePanes(10, 10); // Set frozen line color as red worksheet.setFrozenLineColor(Color.GetBlue()); // Save workbook to ssjson String json = workbook.toJson(); |
You can unfreeze the split panes using the unfreezePanes method of the IWorksheet interface.
To see how freezed panes in a worksheet can be unfreezed, refer to the following example code.
Java |
Copy Code |
---|---|
// Unfreeze all panes in worksheet2
worksheet2.unfreezePanes(); |