Hi:
Hi,
thanks a lot for your reply.
Also. it seems like the sort only works if i sort from column A. it doesn’t work if i sort from column B.
Hi,yuj:
thanks a lot for your reply.I checked that post. it seems like it only shows how to sort multiple columns which exist in one range, such as column A, B and C. But what about column A, D and W, which are not in a sequence and can't be created a range?thanks.
Thanks for your posting and using Aspose.Cells.
I tried to sort non-contiguous columns using Microsoft Excel and it did not allow to sort them. It showed me an error message as shown in the screenshot. So this feature is neither possible with Microsoft Excel nor with Aspose.Cells.
Hi,yuj:
Also. it seems like the sort only works if i sort from column A. it doesn't work if i sort from column B.
Thanks for your posting and using Aspose.Cells.
I have tested this issue with the following sample code with the attached source excel file and it sorted columns A, B, C with respect to column B successfully. I tested the code with the latest version: Aspose.Cells for .NET v8.4.2.5.
I have also attached the output excel file generated by the code for your reference.
C#
//Load a template file.
Workbook workbook = new Workbook("source.xlsx");
//Get the workbook datasorter object.
DataSorter sorter = workbook.DataSorter;
//Set the first order for datasorter object.
sorter.Order1 = Aspose.Cells.SortOrder.Descending;
//Sort with respect to column B
sorter.Key1 = 1;
//Create a cells area (range).
CellArea ca = CellArea.CreateCellArea("A1", "C20");
//Sort data in the specified data range (A1:B14)
sorter.Sort(workbook.Worksheets[0].Cells, ca);
//Save the excel file.
workbook.Save("output.xlsx");