How to debug slow Office application interop constructor?

后端 未结 2 748
小鲜肉
小鲜肉 2021-01-17 15:48

I have an application which deals with excel. Recently I encountered a problem with very slow creation of Excel object.

I\'ve recreated the issue with this s

2条回答
  •  耶瑟儿~
    2021-01-17 16:08

    I don't think the problem is with this constructor. Try to create the object dynamically:

    var obj = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));
    

    Then cast it to Microsoft.Office.Interop.Excel.Application:

    var xlApp = (Microsoft.Office.Interop.Excel.Application)obj;
    MessageBox.Show(xlApp.Name);
    

    I'd expect the slow-down to move to the Activator.CreateInstance call.

    Anyway, you can try to work it around by placing the following into you app.config file (more details):

    
        
    
    

    I'd also suggest to make sure you're running the latest VSTO Runtime and the latest Office PIAs.

提交回复
热议问题