Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 02, 2011 06:15 PM by asi80
Member
12 Points
44 Posts
Jan 02, 2011 01:09 PM|LINK
Hello,
I'm using the following for reading an Excel file
Microsoft.Office.Interop.Excel;
System.Runtime.InteropServices;
protected void btnReadExcel_Click(object sender, EventArgs e) { string Path = @"C:\test.xlsx"; Application _excelApp = new Application(); try { Workbook workbook = _excelApp.Workbooks.Open(Path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); ExcelScanIntenal(workbook); //clean up workbook.Close(false, Path, null); Marshal.ReleaseComObject(workbook); } catch { //........... } }
my problem is that the Excel.EXE processes is hanging on... and still appears in task manager.
also tried Marshal.ReleaseComObject(_excelApp ) with no success.
How do I make sure the Excel process is closed?
thanks
All-Star
137698 Points
22155 Posts
Moderator
MVP
Jan 02, 2011 01:15 PM|LINK
It's not enough. You should still make the same with _excelApp and to all references( and take care : range r = ...; r.Font.Bold = true - means assigning a new var to r.font and release those)...
Jan 02, 2011 06:15 PM|LINK
no need. I got it, thanks
asi80
Member
12 Points
44 Posts
releasing Excel process from memory
Jan 02, 2011 01:09 PM|LINK
Hello,
I'm using the following for reading an Excel file
Microsoft.Office.Interop.Excel;
System.Runtime.InteropServices;
protected void btnReadExcel_Click(object sender, EventArgs e) { string Path = @"C:\test.xlsx"; Application _excelApp = new Application(); try { Workbook workbook = _excelApp.Workbooks.Open(Path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); ExcelScanIntenal(workbook); //clean up workbook.Close(false, Path, null); Marshal.ReleaseComObject(workbook); } catch { //........... } }my problem is that the Excel.EXE processes is hanging on... and still appears in task manager.
also tried Marshal.ReleaseComObject(_excelApp ) with no success.
How do I make sure the Excel process is closed?
thanks
ignatandrei
All-Star
137698 Points
22155 Posts
Moderator
MVP
Re: releasing Excel process from memory
Jan 02, 2011 01:15 PM|LINK
It's not enough. You should still make the same with _excelApp and to all references( and take care : range r = ...; r.Font.Bold = true - means assigning a new var to r.font and release those)...
asi80
Member
12 Points
44 Posts
Re: releasing Excel process from memory
Jan 02, 2011 06:15 PM|LINK
no need. I got it, thanks