类范围的方法sorting失败c# – excel

我正在尝试使用c#使用Microsoft.Office.Interop.Excelsorting列,我得到一个“类范围失败的方法sorting”错误。 代码是:

Excel.Workbook theWorkbook = objApp.Workbooks.Open("D:/rank.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); Excel.Sheets sheets = theWorkbook.Sheets; Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(2); Excel.Range oRng = worksheet.get_Range("E4", "E100"); oRng.Activate(); oRng.Cells.Select(); oRng.Sort(Type.Missing, Excel.XlSortOrder.xlAscending,Type.Missing, Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing,Excel.XlSortOrder.xlAscending, Excel.XlYesNoGuess.xlNo, Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns,Excel.XlSortMethod.xlPinYin, Excel.XlSortDataOption.xlSortNormal,Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal); theWorkbook.Save(); theWorkbook.Close(); objApp.Quit(); Marshal.ReleaseComObject(objApp); 

我错过了什么吗?

电子表格不受保护,并没有密码来打开它(我试过一个简单的电子表格,有一列30行,也不工作)

如果有人可以帮忙,我会非常感激。

提前致谢。

问候,

尝试在Excel中编写macros,然后在C#中实现保存的VB代码。

 oRng.Sort("This should be column name you going sort", Excel.XlSortOrder.xlAscending, Type.Missing, Type.Missing, Excel.XlSortOrder.xlAscending, Type.Missing,Excel.XlSortOrder.xlAscending, Excel.XlYesNoGuess.xlNo, Type.Missing, Type.Missing, Excel.XlSortOrientation.xlSortColumns, Excel.XlSortMethod.xlPinYin, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal, Excel.XlSortDataOption.xlSortNormal)