Create Excel Group in C#, VB.NET

Excel group separate data in Excel worksheet into several groups. Each group may present information of one item. For example, there is a worksheet about sales information about several kinds of products. Users can collect one kind of product in a group to distinguish products type.

Spire.XLS for .NET, an easy-to-use component to manipulate Microsoft Excel workbooks, enables users to create Excel group by using C#, VB.NET. This guide will show the easiest method to realize this function via Spire.XLS for .NET.

Download and install Spire.XLS for .NET. Then invoke sheet.GroupByRows(int firstRow, int lastRow, bool isCollapsed) method to create Excel group by rows. If you want to create group by columns, invoke sheet.GroupByColumns() method directly. After running, you can get the following result:

Create Excel Group

using Spire.Xls;

namespace ExcelGroup
    class Group
        static void Main(string[] args)
            Workbook workbook = new Workbook();
            Worksheet sheet = workbook.Worksheets[0];

            sheet.GroupByRows(2, 9, true);

            workbook.SaveToFile("Group.xlsx", ExcelVersion.Version2010);
Imports Spire.Xls

Namespace ExcelGroup
	Friend Class Group
		Shared Sub Main(ByVal args() As String)
			Dim workbook As New Workbook()
			Dim sheet As Worksheet = workbook.Worksheets(0)

			sheet.GroupByRows(2, 9, True)

			workbook.SaveToFile("Group.xlsx", ExcelVersion.Version2010)
		End Sub
	End Class
End Namespace