问题
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