我可以在C#应用程序中使用Microsoft.Office.Interop.Excel轻松地对列进行排序。但是,建议不要使用Microsoft.Office.Interop.Excel.dll,因此我将代码更改为使用Open XML SDK。
我需要帮助来使用OPEN XML替换以下代码来对列进行排序:
public void SortGEMAccruals(Excel.Worksheet AlignReportSheet,int HeaderRow, int lastRow, int lastColumn)
{Excel.Range SortKey1,SortKey2,SortKey3, SortRange;
SortRange = AlignReportSheet.Range[AlignReportSheet.Cells[HeaderRow, "A"], AlignReportSheet.Cells[lastRow, lastColumn]];
SortKey1 = AlignReportSheet.Range[AlignReportSheet.Cells[HeaderRow, "L"], AlignReportSheet.Cells[lastRow, "L"]];
AlignReportSheet.Sort.SortFields.Clear();
AlignReportSheet.Sort.SetRange(SortRange);
AlignReportSheet.Sort.SortFields.Add(SortKey1, 0, Excel.XlSortOrder.xlAscending);
AlignReportSheet.Sort.Header = Excel.XlYesNoGuess.xlYes;
AlignReportSheet.Sort.Orientation = Excel.XlSortOrientation.xlSortColumns;
AlignReportSheet.Sort.SortMethod = Excel.XlSortMethod.xlPinYin;
AlignReportSheet.Sort.Apply();
}