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 tutorial, we explore the process of grouping and ungrouping rows and columns in Excel using the IronXL library. The video provides a step-by-step guide, starting with the installation of IronXL via the NuGet package manager. The tutorial then progresses to importing the IronXL namespace to access essential Excel functionalities. An existing Excel spreadsheet is loaded into a workbook object, and the default worksheet is obtained. The code demonstrates how to group rows 1 to 8 and columns A to F using the GroupRows
and GroupColumns
methods, respectively. Parameters specify the starting and ending indexes. Optional steps to ungroup rows or columns are also discussed. After saving the changes to a new Excel file named grouped.xlsx
, the tutorial shows how the grouped rows and columns appear with expandable and collapsible buttons for easy data navigation. With just a few lines of C# code, users can significantly improve their Excel data management. The tutorial concludes by encouraging viewers to subscribe for more insights and offers a free trial license for further exploration of Iron software.
Here's the corrected and documented C# code for the tutorial:
// Import necessary IronXL namespace
using IronXL;
class ExcelGroupUngroup
{
static void Main()
{
// Load the existing Excel spreadsheet
WorkBook workbook = WorkBook.Load("example.xlsx");
// Obtain the default worksheet
WorkSheet worksheet = workbook.DefaultWorkSheet;
// Group rows from 1 to 8
// Note: IronXL uses zero-based indexing, so rows 1 to 8 are specified by indices 0 to 7
worksheet.GroupRows(0, 7);
// Group columns from A to F
// Columns A to F correspond to indices 0 to 5
worksheet.GroupColumns(0, 5);
// Optional: Ungroup rows if needed
// worksheet.UngroupRows(0, 7);
// Optional: Ungroup columns if needed
// worksheet.UngroupColumns(0, 5);
// Save the changes to a new Excel file
workbook.SaveAs("grouped.xlsx");
// Output result to console
System.Console.WriteLine("Excel file has been grouped and saved as 'grouped.xlsx'.");
}
}
// Import necessary IronXL namespace
using IronXL;
class ExcelGroupUngroup
{
static void Main()
{
// Load the existing Excel spreadsheet
WorkBook workbook = WorkBook.Load("example.xlsx");
// Obtain the default worksheet
WorkSheet worksheet = workbook.DefaultWorkSheet;
// Group rows from 1 to 8
// Note: IronXL uses zero-based indexing, so rows 1 to 8 are specified by indices 0 to 7
worksheet.GroupRows(0, 7);
// Group columns from A to F
// Columns A to F correspond to indices 0 to 5
worksheet.GroupColumns(0, 5);
// Optional: Ungroup rows if needed
// worksheet.UngroupRows(0, 7);
// Optional: Ungroup columns if needed
// worksheet.UngroupColumns(0, 5);
// Save the changes to a new Excel file
workbook.SaveAs("grouped.xlsx");
// Output result to console
System.Console.WriteLine("Excel file has been grouped and saved as 'grouped.xlsx'.");
}
}
' Import necessary IronXL namespace
Imports IronXL
Friend Class ExcelGroupUngroup
Shared Sub Main()
' Load the existing Excel spreadsheet
Dim workbook As WorkBook = WorkBook.Load("example.xlsx")
' Obtain the default worksheet
Dim worksheet As WorkSheet = workbook.DefaultWorkSheet
' Group rows from 1 to 8
' Note: IronXL uses zero-based indexing, so rows 1 to 8 are specified by indices 0 to 7
worksheet.GroupRows(0, 7)
' Group columns from A to F
' Columns A to F correspond to indices 0 to 5
worksheet.GroupColumns(0, 5)
' Optional: Ungroup rows if needed
' worksheet.UngroupRows(0, 7);
' Optional: Ungroup columns if needed
' worksheet.UngroupColumns(0, 5);
' Save the changes to a new Excel file
workbook.SaveAs("grouped.xlsx")
' Output result to console
System.Console.WriteLine("Excel file has been grouped and saved as 'grouped.xlsx'.")
End Sub
End Class
Further Reading: How to Group and Ungroup Rows & Columns