Excel Freeze Pane allows users to freeze row or column to keep one area always visible when scrolling. It is usual to freeze top row or left column. Also, users can freeze specified rows or columns in one area. For example, we can freeze the first three rows which contain labels to keep them always visible when scrolling down to get other data information in worksheet.
Spire.XLS for .NET, a professional component to operate Excel files, enables uses to freeze panes in Excel. And this guide will show you how to freeze by using C#, VB.NET. Users can invoke sheet.FreezePanes(int rowIndex, int columnIndex) method to set freezing area. The following screenshot shows the result after freezing panes.
Download and install Spire.XLS for .NET and use the following code to freeze panes.
Code Sample:
using System; using Spire.Xls; using System.Drawing; namespace FreezePane { class Program { static void Main(string[] args) { //Load File Workbook workbook = new Workbook(); workbook.LoadFromFile (@"E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx"); Worksheet sheet = workbook.Worksheets[0]; //Freeze Top Row sheet.FreezePanes(2, 1); //Save and Launch workbook.SaveToFile("FreezePane.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start(workbook.FileName); } } }
Imports System Imports Spire.Xls Imports System.Drawing Namespace FreezePane Friend Class Program Shared Sub Main(ByVal args() As String) 'Load File Dim workbook As New Workbook() workbook.LoadFromFile ("E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx") Dim sheet As Worksheet = workbook.Worksheets(0) 'Freeze Top Row sheet.FreezePanes(2, 1) 'Save and Launch workbook.SaveToFile("FreezePane.xlsx", ExcelVersion.Version2010) System.Diagnostics.Process.Start(workbook.FileName) End Sub End Class End Namespace
The above code is used to freeze top row, if you want to freeze the first column, please use this line of code: sheet.FreezePanes(1,2);
Spire.XLS is a professional Excel component which enables developers/programmers to fast generate, read, write and modify Excel document for .NET and Silverlight. It supports C#, VB.NET, ASP.NET, ASP.NET MVC and Silverlight.