Adding formula to cell Exception from HRESULT: 0x800A03EC

前端 未结 4 1939
萌比男神i
萌比男神i 2021-01-23 00:04

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

4条回答
  •  深忆病人
    2021-01-23 00:51

    Hans Passant is correct, but there may be additional settings needed to enable Excel's ability to handle the cadence of your code operations.

    Here's a good set of options to make Excel capable of processing requests faster: Turn Automatic Calculations Off/On

    A summary of what worked for me:

        using Excel = Microsoft.Office.Interop.Excel;
    
        public class ExcelAppWrapper : IDisposable
        {
            private Excel.Application _application;
    
            public ExcelAppWrapper()
            {
                _application = new Excel.Application { Visible = true };
                _application.Workbooks.Add(Missing.Value);
                //there must be a workbook before setting Application.Calculation
                ConfigureApplication(false);
            }
    
            public void Dispose()
            {
                ConfigureApplication(true);
            }
    
            private void ConfigureApplication(bool enable)
            {
                _application.Calculation = enable ? XlCalculation.xlCalculationAutomatic : XlCalculation.xlCalculationManual;
                _application.EnableEvents = enable;
                _application.ScreenUpdating = enable;
                _application.DisplayStatusBar = enable;
            }
        }
    
    

提交回复
热议问题