Spire.XLS

This section aims at providing developers a solution on how to delete Excel rows and columns in C#, VB.NET via this .NET Excel component Spire.XLS for .NET.

Spire.XLS for .NET enables users to delete any Excel rows and columns through two methods: Spire.Xls.Worksheet.DeleteRow(int index) and Spire.Xls.Worksheet.DeleteColumn(int index). Please allow me to give a short description about Spire.XLS for .NET if you are a new visitor here.

Spire.XLS for .NET is a library which provides developers an incredible wealth of features to handle Excel documents without using MS Excel or any third party libraries. Here you can download Spire.XLS for .NET. Then, install it on your system. Since you will use Spire.XLS for .NET, you have to add Spire.XLS.dll as reference from the Bin folder after you start a project in Visual Studio. The default path is “..\Spire.XLS\Bin\NET4.0\ Spire.XLS.dll”. Below is the whole code in my project:

[C#]
//initialize a new Workbook object 
Workbook workbook = new Workbook();
//open an excel file
workbook.LoadFromFile(@"..\excel.xlsx");
//get the first worksheet 
Worksheet sheet = workbook.Worksheets[0];
//delete the twelfth row of the first sheet
sheet.DeleteRow(12);
//delete the second column of the first sheet
sheet.DeleteColumn(2); 
//save the excel file
workbook.SaveToFile("sample.xlsx", ExcelVersion.Version2010);
//launch the excel file
System.Diagnostics.Process.Start(workbook.FileName);

 

[VB.NET]
'initialize a new Workbook object 
Dim workbook As New Workbook()
'open an excel file
workbook.LoadFromFile("..\excel.xlsx")
'get the first worksheet 
Dim sheet As Worksheet = workbook.Worksheets(0)
'delete the twelfth row of the first sheet
sheet.DeleteRow(12)
'delete the second column of the first sheet
sheet.DeleteColumn(2)
'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, data of row 12 and column B in the original Excel file is deleted, you can make a comparison of both original Excel file and the target Excel file as below:

Delete Excel Rows and Columns

original Excel file.jpg

Delete Excel Rows and Columns

delete rows and columns.jpg 

In this section, I have introduced a solution on how to delete Excel rows and columns in C#, VB.NET. From above code, you may find that it is very easy for Spire.XLS for .NET users to finish the delete row and column task. If you have any questions, comments and suggestions, you can put them on E-iceblue Forum. We guarantee to give prompt reply.

Spire.XLS for .NET is an Excel library which allows developers to create, read, edit and manipulate Excel files in C#, VB.NET.

More about this .NET Excel Library

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

This section aims at providing developers a solution on how to insert Excel background image in C#, VB.NET via a .NET Excel library Spire.XLS for .NET.

Spire.XLS for .NET enables you to add background image in your Excel file by setting BackgroundImage property of the object PageSetup to be the image you want to insert, you can see the code here: Spire.Xls.Worksheet.PageSetup.BackgroundImage. Now let us start our task.

Task: Insert Background Image in Excel File

If you are not familiar with Spire.XLS for .NET, please allow me to give a short description of it. Spire.XLS for .NET is an Excel application which enables users to perform a wide range of processing tasks in Excel documents such as generate, edit and handle Excel files in C#.

You will use Spire.XLS for .NET, so we can download Spire.XLS for .NET first. After installing it on system, please start your project either in C# Console Application or VB.NET Console Application. You also can create your project in Windows Forms Application. Please do not forget to add Spire.Xls as reference. The default path is “..\Spire.XLS\Bin\Bin\NET4.0\ Spire.XLS.dll”. Below shows the whole code of my project:

[C#]
//initialize a new instance of Workbook
Workbook workbook = new Workbook();
//import an Excel file from system
workbook.LoadFromFile(@"..\Excel background image.xlsx");
//get the first worksheet
Worksheet sheet = workbook.Worksheets[0];
//open an image 
Bitmap bm = new Bitmap(Image.FromFile(@"..\butterflytable.jpg"));
//set the image to be background image of the worksheet
sheet.PageSetup.BackgoundImage = bm;
//save excel file
workbook.SaveToFile("result.xlsx");
//launch the file
System.Diagnostics.Process.Start("result.xlsx");
[Visual Basic]
'initialize a new instance of Workbook
Dim workbook As New Workbook()
'import an Excel file from system
workbook.LoadFromFile("..\Excel background image.xlsx")
'get the first worksheet
Dim sheet As Worksheet = workbook.Worksheets(0)
'open an image 
Dim bm As New Bitmap(Image.FromFile("..\butterflytable.jpg"))
'set the image to be background image of the worksheet
sheet.PageSetup.BackgoundImage = bm
'save excel file
workbook.SaveToFile("result.xlsx")
'launch the file
System.Diagnostics.Process.Start("result.xlsx")
          

Output File:

After executing above code, I successfully add background image in Excel file, you can see the output file as below:

Insert Excel Background Image

In this section, I have introduced the detail solution on how to insert background image in Excel file with C#, VB.NET. I wish it can help you. If you have any questions, comments or advice, you can add it at E-iceblue Forum, our professionals will give prompt reply.

Spire.XLS for .NET is a .NET Excel component which is designed to meet customers’ need on programming with rich capability and high efficiency.

More about this .NET Excel Library
Page 1 of 25