用的是葡萄城的spread wpf产品,在用worksheet.addrows()方法时会报“集合枚举已改变的异常”,代码如下:
worksheet.SuspendCalcService();
worksheet.SuspendSpanModelEvent();
int count = tables.Count - 1;
int rowcount = worksheet.Rows.Count;
int columncount = worksheet.Columns.Count;
for (int i = 1; i <= count; i++)
{
worksheet.AddRows(rowcount * i, rowcount);
for (int j = 0; j < rowcount; j++)
{
worksheet.Rows[j + rowcount * i].Height = worksheet.Rows[j].Height;
}
worksheet.CopyTo(0, 0, rowcount * i, 0, rowcount, columncount, CopyToOption.All);
}
异常报在标红的那行,异常内容如下:
System.InvalidOperationException: 集合已修改;可能无法执行枚举操作。
在 System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
在 System.Collections.Generic.Dictionary`2.KeyCollection.Enumerator.MoveNext()
在 GrapeCity.Windows.SpreadSheet.Data.eb.d(Int32 A_0)
在 GrapeCity.Windows.SpreadSheet.Data.eb.d(Int32 A_0, Int32 A_1)
在 GrapeCity.Windows.SpreadSheet.Data.Worksheet.AddRows(Int32 row, Int32 count, SheetArea sheetArea)
请高手帮忙看一下这个问题如何解决,先谢谢了 |
|