我的代码如下:
Parallel.ForEach(listSheets, (xlWorkSheet1) =>
{
// Excel.Worksheet xlWorkSheet1 = (Excel.Worksheet)excelbk.Worksheets["Sheet1"];
xlRange = (Excel.Range)xlWorkSheet1.Cells[xlWorkSheet1.Rows.Count, 1];
lock (xlRange)
{
// nRows = (long)xlRange.get_End(Excel.XlDirection.xlUp).Row;
nRows = xlWorkSheet1.UsedRange.Cells.Rows.Count;
xlRange = (Excel.Range)xlWorkSheet1.Rows["5:" + nRows, Type.Missing];
xlRange.Sort(xlRange.Columns[clnum1, Type.Missing],
Excel.XlSortOrder.xlAscending,
xlRange.Columns[clnum2, Type.Missing],
Type.Missing,
Excel.XlSortOrder.xlAscending,
Type.Missing,
Excel.XlSortOrder.xlAscending,
Excel.XlYesNoGuess.xlNo,
Type.Missing,
Type.Missing,
Excel.XlSortOrientation.xlSortColumns,
Excel.XlSortMethod.xlStroke,
Excel.XlSortDataOption.xlSortTextAsNumbers,
Excel.XlSortDataOption.xlSortNormal,
Excel.XlSortDataOption.xlSortNormal);
Console.WriteLine("Sheet{0} have been sorted", xlWorkSheet1.Name);
}
}
listSheets 被定义为一个列表,当我调试它时,它显示错误,该问题的 COM 异常已经运行。
System.Runtime.InteropServices.COMException 应用程序正忙 (RPC_E_CALL_REJECTED 0x80010001) 调用被被调用者拒绝 (RPC_E_SERVERCALL_RETRYLATER 0x8001010A)