写入Excel单元格时,从HRESULT:0x800A03EC发生Excelexception

我知道这里已经讨论过了,但是我找不到解决scheme。 我在C#中使用Microsoft.Office.Interop.Excel时遇到此错误(HRESULT的exception:0x800A03EC)。 这是我的代码:

for (int i = 1; i <= max; i++) { int column = 1 ... double averageDistance = sum / distanceCount; //sum and distanceCount are type double myWorksheet1.Cells[i, column] = averageDistance; // Here I am getting the exception. column++; ... } 

我知道有些人使用Cells中的非零索引来解决这个问题,但是你可以看到我的索引从1开始。任何人都可以帮忙吗? 谢谢。

是因为你没有改变细胞的价值?

试试:myWorksheet1.Cells [i,column] .Value = averageDistance;