@arshad3641
Aspose.Cells supports the feature of sorting by custom list. Please see the following sample code in C# and Java. Please also see the sample Excel file used inside the code and the output Excel file generated by it for a reference.
Download Link:
sample and outputSortedCustomList.zip (12.6 KB)
C#
//Load sample workbook
Workbook wb = new Workbook("sampleSortedCustomList.xlsx");
//Access first worksheet
Worksheet ws = wb.Worksheets[0];
//Cell area to be sorted
CellArea ca = CellArea.CreateCellArea("A1", "A100");
//Add key to sort with custom list
wb.DataSorter.AddKey(0, SortOrder.Ascending, "Car,Pear,Mango,Apple,Banana,Cycle");
//Sort the data
wb.DataSorter.Sort(ws.Cells, ca);
//Save the workbook
wb.Save("outputSortedCustomList.xlsx");
Java
//Load sample workbook
Workbook wb = new Workbook(dirPath + "sampleSortedCustomList.xlsx");
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Cell area to be sorted
CellArea ca = CellArea.createCellArea("A1", "A100");
//Add key to sort with custom list
wb.getDataSorter().addKey(0, SortOrder.ASCENDING, "Car,Pear,Mango,Apple,Banana,Cycle");
//Sort the data
wb.getDataSorter().sort(ws.getCells(), ca);
//Save the workbook
wb.save(dirPath + "outputSortedCustomList.xlsx");