对Excel的Table排序如何多线程

hoolooday 2012-11-19 10:08:38
  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为excel的table泛型列表.
但是,每次都会说调用sort的方法已经在使用中,我尝试用lock
好像不得心啊
...全文
70 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧