【问题标题】:Excel Exception from HRESULT: 0x800A03EC when writing to a Excel cell来自 HRESULT 的 Excel 异常:写入 Excel 单元格时出现 0x800A03EC
【发布时间】:2018-08-06 22:13:47
【问题描述】:

我知道这里已经讨论过了,但我找不到解决方案。 在 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++;
  ...
 }

我知道有些人在 Cells[,] 中使用基于非零的索引解决了这个问题,但是您可以看到我的索引从 1 开始。有人可以帮忙吗? 谢谢。

【问题讨论】:

  • 遇到错误时 i 和 column 的实际值是多少?粘贴不完整的代码示例也无济于事。现在看起来很奇怪而且不清楚。有一个 column=1 和 column++ 但没有在列上循环。

标签: c# excel hresult


【解决方案1】:

是不是因为你没有改变单元格的值?

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

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-13
      • 2013-03-13
      • 1970-01-01
      • 2017-07-12
      相关资源
      最近更新 更多