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

    DsExcel provides the ability to freeze panes in a worksheet. This feature enables users to keep some specific rows or columns visible while scrolling through the rest of the sheet. This functionality is particularly useful when there is a large amount of data 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.

    Freeze Panes

    You can freeze panes in a worksheet using the FreezePanes() method of the IWorksheet interface. This method will freeze the split panes according to the incoming 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 FreezeRow and FreezeColumn properties respectively.

    Refer to the following example code to see how you can freeze panes in a worksheet.

    C#
    Copy Code
    // Adding worksheets to the workbook
    IWorksheet worksheet1 = workbook.Worksheets[0];
    IWorksheet worksheet2 = workbook.Worksheets.Add();
    IWorksheet worksheet3 = workbook.Worksheets.Add();
    IWorksheet worksheet4 = workbook.Worksheets.Add();
    //Freeze Panes
    worksheet1.FreezePanes(2, 3);
    worksheet2.FreezePanes(0, 2);
    worksheet3.FreezePanes(3, 0);
    worksheet4.FreezePanes(3, 5);

    You can also set custom color of lines of frozen panes using the FrozenLineColor property of IWorksheet interface.

    Refer to the following example code to set blue color for lines of frozen panes in a worksheet.

    C#
    Copy Code
    //Use sheet index to get worksheet
    IWorksheet worksheet = workbook.Worksheets[0];
    
    //Freeze panes
    worksheet.FreezePanes(5, 5);
    
    //Set frozen line color as blue
    worksheet.FrozenLineColor = Color.Blue;
    
    //Export workbook to json string and save to ssjson
    System.IO.File.WriteAllText("frozenlinecolor.ssjson", workbook.ToJson());

    Unfreeze Panes

    You can unfreeze the split panes using the UnfreezePanes() method of the IWorksheet interface.

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

    C#
    Copy Code
    //UnFreeze Panes
    worksheet4.UnfreezePanes();