C#如何对工作表的所有列进行排序

时间:2017-08-03 09:55:47

标签: c# excel sorting

我只遇到过对3列进行排序的示例,并且无法弄清楚如何(或者甚至可能)对从第一列到最后一列的所有列进行排序。

我有以下代码按3个特定列进行排序:

//Sort the range based on 1st, 3rd, and 8th
oRng.Sort(oRng.Columns[1, Type.Missing], Excel.XlSortOrder.xlAscending,
oRng.Columns[3, Type.Missing], Type.Missing, Excel.XlSortOrder.xlAscending,
oRng.Columns[8, Type.Missing], Excel.XlSortOrder.xlAscending,
Excel.XlYesNoGuess.xlGuess, Type.Missing, Type.Missing,
Excel.XlSortOrientation.xlSortColumns, Excel.XlSortMethod.xlPinYin,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal);

我的工作表有10列,那么我将如何进行排序?

我还尝试了以下代码,但它似乎只按第一列排序

Excel.Range tempRange = clsWorksheet.UsedRange;
oRng.Sort(tempRange,
Excel.XlSortOrder.xlAscending,
Type.Missing, Type.Missing,
Excel.XlSortOrder.xlAscending,
Type.Missing,
Excel.XlSortOrder.xlAscending,
Excel.XlYesNoGuess.xlGuess,
Type.Missing,
Type.Missing,
Excel.XlSortOrientation.xlSortColumns,
Excel.XlSortMethod.xlPinYin,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal);

0 个答案:

没有答案