Adding formula to cell Exception from HRESULT: 0x800A03EC

一个人想着一个人 提交于 2019-12-31 03:23:05

问题


I'm trying to add a formula to cell but i got the error Exception from HRESULT: 0x800A03EC There are lots of posts with similar issues however none could help me plus i'm not doing any fancy formula's what i'm doing wrong?

 Thread.CurrentThread.CurrentCulture =
 new System.Globalization.CultureInfo("en-US");
 workbook = application.Workbooks.Open(Helper.GetLocalInstalationFolder() +
             @"\IMC.xltx", 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false,
                                                       false, 0, true, 1, 0);
 worksheet = workbook.Worksheets["Report"];
 var rowValue = 0;
 for (int i = 2; i <= LastRow; i++)
 {
     rowValue = i - 1;
     for (int j = 1; j <= 37; j++)
     {
          worksheet.Cells[i, j] = MyArray[rowValue, j];

     }
     // I tried all the following all give the same exception:
     worksheet.Range[i, 38].Formula = "=3+4"; 
     worksheet.get_Range("R" + i + "C38").FormulaR1C1 = "=3+4";
     worksheet.Range[i, 38].FormulaR1C1 = "=3+4";
     worksheet.get_Range("R" + i + "C38").Formula = "=3+4";
   }

回答1:


It is a crappy exception and doesn't mean anything more than you slamming Excel with processing requests at a rate that it cannot keep up with. Your program essentially looks like a hyper-active user that's entering formulas at a rate of one per microsecond.

The workaround is to go slower by intentionally sleeping or to force Excel to do less work. You will very probably fix it in this case by assigning the Application.Calculation property. Set it to manual before you start putting formulas into cells. And back to auto after you're done.

More good advice in this blog post.




回答2:


Perhaps this brings you into the right direction->

[a link] (http://www.codeproject.com/Questions/470089/Exception-from-HRESULT-0x800A03EC-Error)




回答3:


in my case I was missing double-quotes in the HYPERLINK formula arguments, i.e. the formula itself was wrong. i tried a valid formula, like ..Cell(x,y).Formula = "=MIN(2)" and it worked, therefore that was the case..



来源:https://stackoverflow.com/questions/20422387/adding-formula-to-cell-exception-from-hresult-0x800a03ec

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