How to Remove Excel Columns/Rows
This article shows you how to use C# remove Excel columns/rows. With this solution, you don’t need even open the Excel spreadsheet. As we know, in Microsoft Excel worksheet, we can easily remove Excel columns/rows with a few clicks. However, by using C#, you can also do this job effortlessly.
Use C# to remove Excel columns/rows can be as easy as in Microsoft Excel. With the help of Spire.XLS, a professional .NET Excel component, we can finish the whole job in minutes. Download Spire.XLS and install on system. Follow the simple steps below to remove Excel columns/rows at will.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Xls.dll as reference. The default setting of Spire.Xls.dll is placed under "C:\Program Files\e-iceblue\Spire.Xls\Bin”. Select assembly Spire.Xls.dll and click OK to add it to the project.
using Spire.Xls;
namespace delete
{
class Program
{
static void Main(string[] args)
{
}
}
}
Step 2 Open Excel Document
Put the Excel document which we will remove columns/rows into the project folder. Use the code below to load and open it.
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\Sample.xls");
Worksheet sheet = workbook.Worksheets[0];
Step 3 Remove Excel Columns/Rows
Spire.XLS allows users to remove multiple columns/rows. The sample code below shows how to remove Excel columns/rows at will.
//delete the second row from sheet
sheet.DeleteRow(2);
//delete the seventh and eighth rows from sheet
sheet.DeleteRow(7,2);
//delete the first column of sheet
sheet.DeleteColumn(1);
Step 4 Save and Preview
The following code can help us save the Excel file and preview the Excel worksheet.
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
After finish all coding job, we can fins the Excel file in the project folder bin ->debug. And because we can not see the deleted columns/rows, we can get a capture here.
More about Spire.XLS
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. Click to learn more…
Use C# to remove Excel columns/rows can be as easy as in Microsoft Excel. With the help of Spire.XLS, a professional .NET Excel component, we can finish the whole job in minutes. Download Spire.XLS and install on system. Follow the simple steps below to remove Excel columns/rows at will.
Step 1 Create Project
Create a C# project in Visual Studio and Add Spire.Xls.dll as reference. The default setting of Spire.Xls.dll is placed under "C:\Program Files\e-iceblue\Spire.Xls\Bin”. Select assembly Spire.Xls.dll and click OK to add it to the project.
using Spire.Xls;
namespace delete
{
class Program
{
static void Main(string[] args)
{
}
}
}
Step 2 Open Excel Document
Put the Excel document which we will remove columns/rows into the project folder. Use the code below to load and open it.
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"..\..\Sample.xls");
Worksheet sheet = workbook.Worksheets[0];
Step 3 Remove Excel Columns/Rows
Spire.XLS allows users to remove multiple columns/rows. The sample code below shows how to remove Excel columns/rows at will.
//delete the second row from sheet
sheet.DeleteRow(2);
//delete the seventh and eighth rows from sheet
sheet.DeleteRow(7,2);
//delete the first column of sheet
sheet.DeleteColumn(1);
Step 4 Save and Preview
The following code can help us save the Excel file and preview the Excel worksheet.
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
After finish all coding job, we can fins the Excel file in the project folder bin ->debug. And because we can not see the deleted columns/rows, we can get a capture here.
More about Spire.XLS
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. Click to learn more…