Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 写入Excel单元格时,来自HRESULT:0x800A03EC的Excel异常_C#_Excel_Hresult - Fatal编程技术网

C# 写入Excel单元格时,来自HRESULT:0x800A03EC的Excel异常

C# 写入Excel单元格时,来自HRESULT:0x800A03EC的Excel异常,c#,excel,hresult,C#,Excel,Hresult,我知道这里已经讨论过这一点,但我找不到解决办法。 我在C#中使用Microsoft.Office.Interop.Excel时遇到此错误(HRESULT的例外:0x800A03EC)。 这是我的密码: for (int i = 1; i <= max; i++) { int column = 1 ... double averageDistance = sum / distanceCount; //sum and distanceCount are type doubl

我知道这里已经讨论过这一点,但我找不到解决办法。 我在C#中使用Microsoft.Office.Interop.Excel时遇到此错误(HRESULT的例外: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++;
  ...
 }

for(int i=1;i是否因为您没有更改单元格的值

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

尝试以下操作:

Excel.Application MyApp = new Excel.Application { Visible = false, DisplayAlerts = false };
System.Threading.Thread.CurrentThread.CurrentCulture = new 
System.Globalization.CultureInfo("en-US");

出现错误时,i和column的实际值是多少?粘贴不完整的代码示例也没有帮助。现在看起来很奇怪和不清楚。有一个column=1和column+,但在这些列上没有循环。