Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
not releasing excel objects..pl see this simple code.
Please help...i tried so many things but I can't get all Excel objects
cleaned up. Here is my whole code...if I comment out everything in for() loop below excel objects get cleaned up. otherwise I can see them in Task Manager...its so weird. Appreciate your help. thanks Excel.Application dstExcel = new Excel.ApplicationClass(); Excel._Workbook dstWb = dstExcel.Workbooks.Open(eventdir, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); Excel._Worksheet dstWsh = (Excel._Worksheet)dstWb.Sheets.get_Item(2); int i = 0; string vend, perc; for ( i = 15; i <= 34; i++ ) { if ( ((Excel.Range)dstMsh.Cells[i,4]).Value2 != null ) { perc = ((Excel.Range)dstMsh.Cells[i,4]).Value2.ToString(); } else { perc = ""; } if ( ((Excel.Range)dstMsh.Cells[i,2]).Value2 != null ) { vend = ((Excel.Range)dstMsh.Cells[i,2]).Value2.ToString(); } else { vend = ""; } // process 'perc' and 'vend' strings } // export excel chart Excel.Range chartRange = dstMsh.get_Range("B15", "D" + chartData.ToString()); Excel.ChartObjects chObjs = (Excel.ChartObjects)dstMsh.ChartObjects(Type.Missi ng); Excel.ChartObject chObj = chObjs.Add(100, 200, 300, 200); Excel.Chart chart = chObj.Chart; chart.SetSourceData(chartRange, Type.Missing); chart.ChartArea.AutoScaleFont = false; chart.ChartType = Excel.XlChartType.xlBarClustered; string imgDir = "C:\\inetpub\\wwwroot\\apac2\\images\\"; string imgSaveAs = getCurrentTime()+ "_chart.JPG"; chart.Export(imgDir + imgSaveAs, "JPEG", false); imgChart.Visible = true; imgChart.ImageUrl = "images\\" + imgSaveAs; System.Runtime.InteropServices.Marshal.ReleaseComO bject (chartRange); System.Runtime.InteropServices.Marshal.ReleaseComO bject (chart); System.Runtime.InteropServices.Marshal.ReleaseComO bject (chObjs); System.Runtime.InteropServices.Marshal.ReleaseComO bject (chObj); chartRange = null; chObjs = null; chObj = null; chart = null; System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstMsh); dstMsh = null; dstWb.Close(false, Missing.Value, Missing.Value); dstExcel.Workbooks.Close(); dstExcel.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstExcel); System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstWb); System.Runtime.InteropServices.Marshal.ReleaseComO bject (dstWsh); dstWsh = null; dstWb = null; dstExcel = null; GC.Collect(); |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Releasing arrays? | Excel Discussion (Misc queries) | |||
Simple code crashes Excel | Excel Programming | |||
Releasing all Userforms in memory | Excel Programming | |||
VB6 with Excel Objects: Please review my code | Excel Programming | |||
Question about releasing memory | Excel Programming |