Hide Excel Row and Column in C#, VB.NET

This section is designed to provide developers a solution on how to hide Excel row and column in C#, VB.NET via this .NET Excel library Spire.XLS for .NET.

Spire.XLS for .NET enables you to hide any Excel row and column by two properties of the class Spire.Xls.Worksheet: HideRow(int rowIndex) and HideColumn(int columnIndex). If you are not familiar with Spire.XLS for .NET, please allow me to give a short description about it.

Spire.XLS for .NET is an Excel application which enables users to perform a wide range of processing tasks directly without MS Excel or any third party libraries. You will use Spire.XLS for .NET, so you have to download Spire.XLS for .NET. After installing it on system, you can start your Visual Studio to create a new project either in C# Windows Forms Application or Console Application. You also can use VB.NET.

After creating your project, you can add Spire.XLS.dll as reference in the downloaded Bin folder. The default path is “..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll” Please note that Spire.XLS for .NET supports Framework 2.0 and above. You can see the complete code in my project below:

//initialize a new instance object
Workbook workbook = new Workbook();
//open a template excel file
//get the first worksheet 
Worksheet sheet = workbook.Worksheets[0];
//hide the 12th row of Sheet
//hide the third column  of Sheet
//save the Excel file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010);
//launch the Excel file
'initialize a new instance object
Dim workbook As New Workbook()
'open a template excel file
'get the first worksheet 
Dim sheet As Worksheet = workbook.Worksheets(0)
'hide the 12th row of Sheet1
'hide the third column  of Sheet1
'save the Excel file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010)
'launch the Excel file

Output File:

After executing above code, row 12 and column C are hided from the first worksheet, you can see the task result as below:

Hide Excel Row and Column

In this section, I have introduced the solution on how to hide excel row and column in C#, VB.NET. Even the code is very simple, I wish it can help you and give you some insights. If you have any comments, comments or suggestions, you can put them on E-iceblue Forum. We will give prompt reply.