zimmer9
asked on
How to ensure I don't keep keep creating additional EXCEL.EXE processes each time I call a routine in C# from a loop?
I am developing a C# Windows application using VS2005.
In the following routine which I call from a loop,
it seems that I create a new EXECEL.EXE process each time this routine is called
according to the Windows Task Manager.
Is there a way to ensure that I drop the EXCEL.EXE before I call this routine the next time?
public static void ExcelFormat(string filename, string footnote)
{
Excel.Application oXL = new Excel.Application();
oXL.Visible = false;
oXL.DisplayAlerts = false;
Excel._Workbook oWB = (Excel._Workbook)oXL.Workb ooks.Open( filename, 0, false, 5, Missing.Value, Missing.Value, false, Missing.Value, Missing.Value, false, false, Missing.Value, false, false, false);
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Acti veSheet;
oSheet.Activate();
try
{
oSheet.get_Range(oSheet.Ce lls[2, 1], oSheet.Cells[65535, 1]).EntireColumn.NumberFor mat = "#,##0";
}
finally
{
oXL.Workbooks.Close();
oXL.Quit();
System.Runtime.InteropServ ices.Marsh al.Release ComObject( oXL);
System.Runtime.InteropServ ices.Marsh al.Release ComObject( oSheet);
System.Runtime.InteropServ ices.Marsh al.Release ComObject( oWB);
oSheet = null;
oWB = null;
oXL = null;
}
}
In the following routine which I call from a loop,
it seems that I create a new EXECEL.EXE process each time this routine is called
according to the Windows Task Manager.
Is there a way to ensure that I drop the EXCEL.EXE before I call this routine the next time?
public static void ExcelFormat(string filename, string footnote)
{
Excel.Application oXL = new Excel.Application();
oXL.Visible = false;
oXL.DisplayAlerts = false;
Excel._Workbook oWB = (Excel._Workbook)oXL.Workb
Excel._Worksheet oSheet = (Excel._Worksheet)oWB.Acti
oSheet.Activate();
try
{
oSheet.get_Range(oSheet.Ce
}
finally
{
oXL.Workbooks.Close();
oXL.Quit();
System.Runtime.InteropServ
System.Runtime.InteropServ
System.Runtime.InteropServ
oSheet = null;
oWB = null;
oXL = null;
}
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.