Hi,
Thanks for your posting and using Aspose.Cells.
Please use the
AddKey() method of
DataSorter to add more keys. Please see the following sample code, its
source excel file and the
output excel file. I have also attached the
screenshot showing the order of values before and after sorting for illustration.
C#
Workbook wb = new Workbook(“sample.xlsx”);
Worksheet ws = wb.Worksheets[0];
CellArea ca = CellArea.CreateCellArea(“A1”, “E35”);
DataSorter sorter = wb.DataSorter;
sorter.AddKey(0, SortOrder.Ascending);
sorter.AddKey(1, SortOrder.Ascending);
sorter.AddKey(2, SortOrder.Ascending);
sorter.AddKey(3, SortOrder.Ascending);
sorter.AddKey(4, SortOrder.Ascending);
sorter.Sort(ws.Cells, ca);
wb.Save(“output.xlsx”);
Java
<span style=“color: rgb(255, 20, 147); font-family: “Courier New”; font-size: small;”>Workbook wb = new Workbook(dirPath + “sample.xlsx”);
Worksheet ws = wb.getWorksheets().get(0);
CellArea ca = CellArea.createCellArea(“A1”, “E35”);
DataSorter sorter = wb.getDataSorter();
sorter.addKey(0, SortOrder.ASCENDING);
sorter.addKey(1, SortOrder.ASCENDING);
sorter.addKey(2, SortOrder.ASCENDING);
sorter.addKey(3, SortOrder.ASCENDING);
sorter.addKey(4, SortOrder.ASCENDING);
sorter.sort(ws.getCells(), ca);
wb.save(dirPath + “output.xlsx”);