【发布时间】:2021-11-06 09:33:18
【问题描述】:
我一直在尝试根据第一列(即日期)对范围进行排序。但是当我运行我的代码时,似乎什么也没发生。文件没有变化。以下是我的代码。
Excel.Application xlApp = new Excel.Application();
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
String file = @"C:\Book1.xlsx";
xlWorkBook = xlApp.Workbooks.Open(file);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
Excel.Range rng = xlWorkSheet.get_Range("B16", "I38");
rng.Sort(rng.Columns[1, Type.Missing], Excel.XlSortOrder.xlDescending,
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);
xlWorkBook.Close(true, misValue, misValue);
【问题讨论】:
标签: c# excel sorting office-interop