Link to home
Start Free TrialLog in
Avatar of oczos
oczos

asked on

Sorte a Datefield in ExcelSheet using C#

Hi Experts,

i try to sort an excelsheet based on a column polulated with date entries.

The problem seems to be, that the dates are handled as text.

What i want:
01.01.2013
02.01.2013
..
01.02.2013
02.02.2013

What i get:
01.01.2013
01.02.2013
..
02.01.2013
02.02.2013

The column (to be precise: The cells in the range to sort) is formated as a "Date" field in the worksheet.

Here is the Code i use:
Excel.Range range = oSheet.get_Range("A4:W" + iLastUsedRow, Type.Missing);

range.Sort(range.Columns[1, Type.Missing], Excel.XlSortOrder.xlAscending,Excel.XlYesNoGuess.xlNo,Type.Missing,Type.Missing,Excel.XlSortOrientation.xlSortColumns,Excel.XlSortMethod.xlPinYin,Excel.XlSortDataOption.xlSortTextAsNumbers);
 
System.Runtime.InteropServices.Marshal.ReleaseComObject(range);

Open in new window


Any help is greatly appreciated!
BR
Tom
ASKER CERTIFIED SOLUTION
Avatar of oczos
oczos

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial