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:
using Spire.Xls; namespace ExcelGroup { class Group { static void Main(string[] args) { Workbook workbook = new Workbook(); workbook.LoadFromFile(@"E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx"); Worksheet sheet = workbook.Worksheets[0]; sheet.GroupByRows(2, 9, true); workbook.SaveToFile("Group.xlsx", ExcelVersion.Version2010); System.Diagnostics.Process.Start("Group.xlsx"); } } }
Imports Spire.Xls Namespace ExcelGroup Friend Class Group Shared Sub Main(ByVal args() As String) Dim workbook As New Workbook() workbook.LoadFromFile("E:\Work\Documents\ExcelFiles\PartSalesInfo.xlsx") Dim sheet As Worksheet = workbook.Worksheets(0) sheet.GroupByRows(2, 9, True) workbook.SaveToFile("Group.xlsx", ExcelVersion.Version2010) System.Diagnostics.Process.Start("Group.xlsx") End Sub End Class End Namespace