How to Unfreeze Excel Panes in C#, VB.NET

Excel Freeze Panes keeps rows and columns visible while the rest of the worksheet scrolls. Likewise, we need to unfreeze Excel panes due to work needs in some cases. This article aims at introducing the solution to unfreeze the Excel top row in c# and VB.NET through a utility Excel .NET library Spire.XLS.

First we need to complete the preparatory work:

  • Download the latest Spire.XLS and install it on your machine.
  • Add the Spire.XLS.dll files as reference.
  • Open bin folder and select the three dll files under .NET 4.0.
  • Right click property and select properties in its menu.
  • Set the target framework as .NET 4.
  • Add Spire.XLS as namespace.

Here comes to the explanation of the C# code:

Step 1: Create an instance of Spire.XLS.Workbook.

Workbook workbook = new Workbook();

Step 2: Load the file base on a specified file path.

workbook.LoadFromFile("sample.xls");

Step 3: Get the first worksheet.

Worksheet sheet = workbook.Worksheets[0];

Step 4: Unfreeze the top row.

sheet.RemovePanes();

Step 5: Save as the generated file.

workbook.SaveToFile("sample.xls",ExcelVersion.Version97to2003);

Please preview the freeze panes effect screenshot:

Excel freeze panes

And the unfreeze panes effect screenshot:

Excel unfreeze panes

Here is the full code in C# and VB.NET:

[C#]
static void Main(string[] args)
{
 Workbook workbook = new Workbook();
 workbook.LoadFromFile("Sample.xls");
 Worksheet sheet = workbook.Worksheets[0];
 sheet.RemovePanes();
 workbook.SaveToFile("sample.xls",ExcelVersion.Version97to2003);
}
[VB.NET]
Private Shared Sub Main(args As String())
	Dim workbook As New Workbook()
	workbook.LoadFromFile("Sample.xls")
	Dim sheet As Worksheet = workbook.Worksheets(0)
	sheet.RemovePanes()
	workbook.SaveToFile("sample.xls",ExcelVersion.Version97to2003)
End Sub