Excel Exception from HRESULT: 0x800A03EC when writing to a Excel cell

≯℡__Kan透↙ 提交于 2019-12-14 03:14:31

问题


I know that this has been discussed here, but I can not find solution. I am getting this error while working with Microsoft.Office.Interop.Excel in C# (Exception from HRESULT: 0x800A03EC). Here is my code:

 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++;
  ...
 }

I know that some people solved this using non-zero based index in Cells[,], but as you can see my indexes are starting from 1. Can anyone help please? Thank you.


回答1:


Is it because you are not changing the Value of the cell?

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




回答2:


Try this:

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


来源:https://stackoverflow.com/questions/35841073/excel-exception-from-hresult-0x800a03ec-when-writing-to-a-excel-cell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!