C#Excel Interop在Excel工作表中排序数据

时间:2014-04-25 07:49:10

标签: c# excel xls excellibrary

我正在使用C#并希望根据两列对某些数据进行排序。我查看了互联网上的各种页面,并提出了以下代码。问题是代码无法编译。

我正在使用Excel 2013&在.Net中,Microsoft Excel对象库是版本15.我可以在Excel中执行我需要做的其他事情,期望对数据进行排序。

它突出显示Type.Missing的sort方法的第3行。它说参数5不能从对象转换为Microsoft.Office.Interop.Excel.XlSortOrder。

 Excel.Range rngSort = _xlWorksheet.get_Range("A2", "J" + lastRow);

        rngSort.Sort(rngSort.Columns[1, Type.Missing], Excel.XlSortOrder.xlAscending,
                        rngSort.Columns[2, Type.Missing], Type.Missing, Excel.XlSortOrder.xlAscending,
                        Type.Missing, Excel.XlSortOrder.xlAscending,
                        Excel.XlYesNoGuess.xlYes, Type.Missing, Type.Missing,
                        Excel.XlSortOrientation.xlSortColumns, 
                        Excel.XlSortMethod.xlPinYin,
                        Excel.XlSortDataOption.xlSortNormal,
                        Excel.XlSortDataOption.xlSortNormal,
                        Excel.XlSortDataOption.xlSortNormal);
        rngSort = null;

0 个答案:

没有答案