Gavin Howard
Posts: 14
Joined: 2016-12-01
|
We're in the process of creating our end to end tests for the excel add-in we have been building and have been having a lot of success using MStest in conjunction with Coded UI tests to drive our add-in panels. What we have been struggling with though, on our test boxes and local developer machines is finding a way to get the correct path to excel.exe programmatically in C#.
We first tried to use interop services by doing something like:
public void UIExcelInit()
{
try
{
Excel.Application app = new Excel.Application();
interopExcelPath = app.Path;
app.Quit();
}
catch(Exception e)
{
Console.WriteLine("There has been an issue locating Excel.exe in this context." + e.Message);
throw;
}
finally
{
if (app != null) System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
}
}
However, this seems to launch an extra few excel.exe process for us which are not cleaned up very quickly before the tests commence execution.
Alternately, we could use the registry entries - but in some contexts the user under which the tests are executing will not have privileges to access the registry.
Is there any way either from some standard C# methodology, Interop services or the ADX libraries to get the path to execl.exe programmatically? |
|
Andrei Smolin
Add-in Express team
Posts: 18793
Joined: 2006-05-11
|
Hello Gavin,
Gavin Howard writes:
However, this seems to launch an extra few excel.exe process for us which are not cleaned up very quickly before the tests commence execution.
Turn off all COM add-ins off for EXCEL.EXE to quit. If the issue occurs with your add-in turned on, this may be a result of your add-in leaving some COM objects unreleased; see https://www.add-in-express.com/creating-addins-blog/2011/11/04/why-doesnt-excel-quit/.
Gavin Howard writes:
Is there any way either from some standard C# methodology, Interop services or the ADX libraries to get the path to execl.exe programmatically?
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName?
Add-in Express doesn't search excel.exe. You may also need totake into account the possibility to have several Excel versions installed.
Andrei Smolin
Add-in Express Team Leader |
|