Unable to open another excel file (when one Excel is opened by .net)

后端 未结 2 1793
执念已碎
执念已碎 2021-01-12 00:43

I have designed a .net application which will open an Excel file at the time of login and use it to print a report. It will be closed while logging out the user. I set visib

2条回答
  •  情书的邮戳
    2021-01-12 01:30

    Looks like your problem is caused by the same instance of xlApp. What I would do is simple: I would initialize new instance of xlApp and then quite that instance of the application. This way it won't interfere with any other open instance of Excel. Here is how I use it in C#:

    using Excel = Microsoft.Office.Interop.Excel;
    
    Excel.Application xlApp = new Excel.Application();  // by default this is invisible
    

    do whatever you have to do with the new instance of xlApp and then quite the application. Once you quite the application it won't be in your task manager.

    xlApp.Application.Quit();
    

    I have designed several applications where I had to process the same Excel files that most likely would've been open by those same users. This approach (opening new instance of excel in invisible mode and then quitting the application) never caused any problems for me.

提交回复
热议问题