We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Prioritize alphabets on symbols in aspose sorting

Hi,

I have a columns with Data
as
AB
A-B
AA
A-A

when we sort is
it’ll be as
A-A
A-B
AA
AB

is there any way we can give ‘-’ as later priority then alphabets.

where I can get the data as
AA
AB
A-A
A-B

Hi,

Thanks for providing us some details.

Well, you may try to use custom sort list for your specific requirements, see the sample code with the template file attached. The output file is also included in the attached zipped archive below:
e.g
Sample code:

Workbook workbook= new Workbook("Bk_sortalphabets1.xlsx");
	Worksheet worksheet = workbook.getWorksheets().get(0);
	Cells cells= worksheet.getCells();
	DataSorter sorter = workbook.getDataSorter();
	
	sorter.addKey(0, SortOrder.ASCENDING,"AA,AB,A-A,A-B");

	CellArea cellArea = CellArea.createCellArea(0, 0, 10, 0);
	
	sorter.sort(cells, cellArea);
	workbook.save("out1bksortalphabets1.xlsx");

files1.zip (15.3 KB)

thanks for the reply. But the data’s will not be constant it can be anything that matter not necessary it will AB, a-b , any word …

@aymarzapak,

How could you do this using data sorting options provided by MS Excel manually? If you could this for any type of data in MS Excel, kindly share the sample Excel file with steps details, we will check how to do it via Aspose.Cells APIs.