1

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

我正在使用 Excel 2013 和 .Net 中的 Microsoft Excel 对象库是第 15 版。我可以在 Excel 中做我需要做的所有其他事情,除了对数据进行排序。

具有 Type.Missing 的排序方法的第 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;
4

0 回答 0