Document Solutions for Excel, Java Edition | Document Solutions
Features / Worksheet / Freeze Trailing Panes in a Worksheet
In This Topic
    Freeze Trailing Panes in a Worksheet
    In This Topic

    DsExcel allows users to freeze trailing panes in a worksheet. The trailing panes correspond to the rows and columns at the extreme bottom and right of the worksheet. Hence, it enables users to keep those specific rows or columns visible while scrolling through the rest of the sheet.

    However, the frozen trailing panes are only visible while interacting with SpreadJS by doing JSON I/O and are not visible in Excel or PDF.

    Freeze Trailing Panes

    The trailing panes in a worksheet can be frozen by using the freezeTrailingPanes method of IWorksheet interface which takes row and column positions as parameters. The number of frozen rows and column can also be retrieved by using the getFreezeTrailingRow and getFreezeTrailingColumn methods respectively.

    Refer to the following example code to freeze trailing panes and retrieve the number of trailing frozen rows and columns in a worksheet.

    Java
    Copy Code
    // Create a new workbook
    Workbook workbook = new Workbook();
    
    // Use sheet index to get worksheet.
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    
    // Freeze trailing pane
    worksheet.freezeTrailingPanes(2, 3);
    
    System.out.println("Number of trailing rows are: " + worksheet.getFreezeTrailingRow()
            + "\nNumber of trailing columns are: " + worksheet.getFreezeTrailingColumn());
    
    // Save workbook to ssjson
    String json = workbook.toJson();
    try {
        BufferedWriter out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream("FreezeTrailingRowsCols.ssjson"), "utf-8"));
        out.write(json);
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Unfreeze Trailing Panes

    Similarly, the frozen trailing panes can be unfrozen by using the unfreezeTrailingPanes method of IWorksheet interface.

    Refer to the following example code to unfreeze trailing panes in a worksheet.

    Java
    Copy Code
    // Create a new workbook
    Workbook workbook = new Workbook();
    
    // Use sheet index to get worksheet.
    IWorksheet worksheet = workbook.getWorksheets().get(0);
    
    // Freeze trailing pane
    worksheet.freezeTrailingPanes(2, 3);
    
    // Unfreeze trailing pane
    worksheet.unfreezeTrailingPanes();
    
    // Save workbook to ssjson
    String json = workbook.toJson();
    try {
        BufferedWriter out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream("UnFreezeTrailingRowsCols.ssjson"), "utf-8"));
        out.write(json);
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }