Apply sorting alphabetic

Hi,

how can I applying sorting to a column ?
I used this code

CellArea range = CellArea.CreateCellArea(“R1”, “R” + wsTaxonomien.Cells.MaxRow);
wsTaxonomien.Workbook.DataSorter.Key1 = 0;
wsTaxonomien.Workbook.DataSorter.Order1 = SortOrder.Ascending;
wsTaxonomien.Workbook.DataSorter.Sort(wsTaxonomien.Cells, range);

to do similar like this
ActiveSheet.Range(“$R:$R”).CurrentRegion.Sort Key1:=Range(“$R:$R”), DataOption1:=xlSortTextAsNumbers, Header:=xlYes

But data was not sorted. What is wrong ?

@Nachti

@Nachti,

Could you please zip and attach the input Excel file and the output Excel file (created by Aspose.Cells after implementing data sorting) for reference? Also, please provide your expected Excel file containing your desired sorted data. We will evaluate your issue and look into it soon.

@Nachti

Please note, Datasorter.Key1 represents the absolute position(column index in your case). When you specified it as 0, it means to sort column A. Please change your code like:

...
wsTaxonomien.Workbook.DataSorter.Key1 = range.StartColum;
...

Thank you @johnson.shi,

that helps but now a face a new issue:

It seems it filter only column ‘R’ but not the rest

This is my code:
CellArea range = CellArea.CreateCellArea(“R”, “R” + wsTaxonomien.Cells.MaxRow);
wsTaxonomien.Workbook.DataSorter.Key1 = range.EndColumn;
wsTaxonomien.Workbook.DataSorter.Order1 = SortOrder.Ascending;
wsTaxonomien.Workbook.DataSorter.Sort(wsTaxonomien.Cells, range);

I add here the content
somefiles.zip (1.1 MB)

I just run this line of VBA code in outputBeforeSort.xlsx
ActiveSheet.Range(“$R:$R”).CurrentRegion.Sort Key1:=Range(“$R:$R”), DataOption1:=xlSortTextAsNumbers, Header:=xlYes
and get the correct result

with the c# code above the other columns content are different

Thanks in advance

@Nachti

Please set the whole data range and change codes as :

   CellArea range = CellArea.CreateCellArea("A1", "AM" + (wsTaxonomien.Cells.MaxRow + 1));
   wsTaxonomien.Workbook.DataSorter.Key1 = CellsHelper.ColumnNameToIndex("R");
   wsTaxonomien.Workbook.DataSorter.HasHeaders = true;