Thursday, 28 February 2013 03:47

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

Written by  support iceblue
Rate this item
(0 votes)

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:

[C#]
//initialize a new instance object
Workbook workbook = new Workbook();
//open a template excel file
workbook.LoadFromFile(@"..\excel.xlsx");
//get the first worksheet 
Worksheet sheet = workbook.Worksheets[0];
//hide the 12th row of Sheet
sheet.HideRow(12);
//hide the third column  of Sheet
sheet.HideColumn(3);
//save the Excel file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010);
//launch the Excel file
System.Diagnostics.Process.Start(workbook.FileName);
          
[VB]
'initialize a new instance object
Dim workbook As New Workbook()
'open a template excel file
workbook.LoadFromFile("..\excel.xlsx")
'get the first worksheet 
Dim sheet As Worksheet = workbook.Worksheets(0)
'hide the 12th row of Sheet1
sheet.HideRow(12)
'hide the third column  of Sheet1
sheet.HideColumn(3)
'save the Excel file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010)
'launch the Excel file
System.Diagnostics.Process.Start(workbook.FileName)
          

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.

Spire.XLS for .NET is a .NET Excel library that meets customers’ need on handling Excel files with high efficiency and reliability.

More about this .NET Excel Library

Additional Info

  • tutorial_title: Hide Excel Row and Column
Last modified on Wednesday, 08 January 2014 02:22