Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Thank you for considering Aspose.
Well, it depends on your requirement whether you want to sort the data first and then group the rows based on sorted data or first group the rows and then perform the sorting. You may try it either way using Aspose.Cells as well. If you find any issue, please share your desired excel file (by creating in MS Excel) and we will check it soon. Also, following is my sample code which sorts the data first and then group the first two rows for your reference:
Sample Code:
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];
Cells cells = worksheet.Cells;
cells[0, 0].PutValue("WorldSoccerCupwinner");
cells[0, 1].PutValue("Year");
cells[0, 2].PutValue("Location");
cells[1, 0].PutValue("<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Italy");
cells[1, 1].PutValue(2006);
cells[1, 2].PutValue("Germany");
cells[2, 0].PutValue("Brazil");
cells[2, 1].PutValue(2002);
cells[2, 2].PutValue("Korea");
cells[3, 0].PutValue("France");
cells[3, 1].PutValue(1998);
cells[3, 2].PutValue("France");
cells[4, 0].PutValue("Brazil");
cells[4, 1].PutValue(1994);
cells[4, 2].PutValue("USA");
cells[5, 0].PutValue("Germany");
cells[5, 1].PutValue(1990);
cells[5, 2].PutValue("Italy");
cells[6, 0].PutValue("Argentina");
cells[6, 1].PutValue(1986);
cells[6, 2].PutValue("Maxico");
cells[7, 0].PutValue("Italy");
cells[7, 1].PutValue(1982);
cells[7, 2].PutValue("Spain");
cells[8, 0].PutValue("Argentina");
cells[8, 1].PutValue(1978);
cells[8, 2].PutValue("Argentina");
cells[9, 0].PutValue("Germany");
cells[9, 1].PutValue(1974);
cells[9, 2].PutValue("Germany");
DataSorter sorter = workbook.DataSorter;
sorter.Order1 = Aspose.Cells.SortOrder.Ascending;
//Define the first key.
sorter.Key1 = 0;
//Create a cells area (range).
CellArea ca = new CellArea();
//Specify the start row index.
ca.StartRow = 1;
//Specify the start column index.
ca.StartColumn = 0;
//Specify the last row index.
ca.EndRow = 9;
//Specify the last column index.
ca.EndColumn = 3;
//Sort data in the specified data range (A1:B14)
sorter.Sort(workbook.Worksheets[0].Cells, ca);
//Grouping first 2 rows
worksheet.Cells.GroupRows(1, 2);
//Saving the modified Excel file in default (that is Excel 2003) format
workbook.Save("C:\\output2.xls", FileFormatType.Default);
Thank You & Best Regards,