Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this video tutorial, you will learn how to manage Excel worksheets using the IronXL library in C#. The tutorial begins by guiding viewers to set up a Visual Studio C# project with IronXL installed. Key tasks demonstrated include creating a new Excel workbook and populating it with four worksheets using the 'create worksheet' method. IronXL's versatility is showcased by shuffling worksheet order, setting an active tab with 'set sheet position,' and removing worksheets. Additionally, viewers learn to clone and rename sheets, saving changes with a different file name for comparison. The tutorial emphasizes the ease of managing Excel files with IronXL, encouraging users to explore further. The video concludes with a call to subscribe for more tips and tricks, and a link is provided to try IronXL software.
Sample Code:
// Necessary using directive to work with IronXL
using IronXL;
class ExcelManagement
{
static void Main()
{
// Create a new workbook
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
// Add four worksheets to the workbook
workbook.CreateWorkSheet("Sheet1");
workbook.CreateWorkSheet("Sheet2");
workbook.CreateWorkSheet("Sheet3");
workbook.CreateWorkSheet("Sheet4");
// Shuffle the order of worksheets
workbook.WorkSheets.Move("Sheet4", 0); // Move Sheet4 to the first position
// Set an active worksheet
workbook.WorkSheets[0].SetActive();
// Remove a worksheet by name
workbook.WorkSheets.Remove("Sheet2");
// Clone and rename a worksheet
var clonedSheet = workbook.WorkSheets["Sheet1"].Clone("Sheet1_Clone");
// Save changes with a different file name
workbook.SaveAs("ManagedExcelFile.xlsx");
// Inform the user about the successful operations
Console.WriteLine("Excel workbook managed successfully.");
}
}
// Necessary using directive to work with IronXL
using IronXL;
class ExcelManagement
{
static void Main()
{
// Create a new workbook
WorkBook workbook = WorkBook.Create(ExcelFileFormat.XLSX);
// Add four worksheets to the workbook
workbook.CreateWorkSheet("Sheet1");
workbook.CreateWorkSheet("Sheet2");
workbook.CreateWorkSheet("Sheet3");
workbook.CreateWorkSheet("Sheet4");
// Shuffle the order of worksheets
workbook.WorkSheets.Move("Sheet4", 0); // Move Sheet4 to the first position
// Set an active worksheet
workbook.WorkSheets[0].SetActive();
// Remove a worksheet by name
workbook.WorkSheets.Remove("Sheet2");
// Clone and rename a worksheet
var clonedSheet = workbook.WorkSheets["Sheet1"].Clone("Sheet1_Clone");
// Save changes with a different file name
workbook.SaveAs("ManagedExcelFile.xlsx");
// Inform the user about the successful operations
Console.WriteLine("Excel workbook managed successfully.");
}
}
' Necessary using directive to work with IronXL
Imports IronXL
Friend Class ExcelManagement
Shared Sub Main()
' Create a new workbook
Dim workbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
' Add four worksheets to the workbook
workbook.CreateWorkSheet("Sheet1")
workbook.CreateWorkSheet("Sheet2")
workbook.CreateWorkSheet("Sheet3")
workbook.CreateWorkSheet("Sheet4")
' Shuffle the order of worksheets
workbook.WorkSheets.Move("Sheet4", 0) ' Move Sheet4 to the first position
' Set an active worksheet
workbook.WorkSheets(0).SetActive()
' Remove a worksheet by name
workbook.WorkSheets.Remove("Sheet2")
' Clone and rename a worksheet
Dim clonedSheet = workbook.WorkSheets("Sheet1").Clone("Sheet1_Clone")
' Save changes with a different file name
workbook.SaveAs("ManagedExcelFile.xlsx")
' Inform the user about the successful operations
Console.WriteLine("Excel workbook managed successfully.")
End Sub
End Class
Further Reading: How to Manage Worksheets