Each time you loop through settings collection, you actually modify the original element in the settings collection. And again when you add settings to results, you actually add the same references again and again. Later changes on the original element (s) affect all the elements int the result list pointing to the same element.
So, you should create a copy from s before modifying and storing it to another collection if you want the elements to have independent values.
// I have used this function still problem persists
protected void killExcel(Microsoft.Office.Interop.Excel.Application exc)
List<microsoft.office.interop.excel.workbook> wbs = new List<microsoft.office.interop.excel.workbook>();
List<microsoft.office.interop.excel.worksheet> wss = new List<microsoft.office.interop.excel.worksheet>();
foreach (Microsoft.Office.Interop.Excel.Workbook wb in exc.Workbooks)
foreach (Microsoft.Office.Interop.Excel.Worksheet ws in wb.Worksheets)
wss.Add(ws); // collect worksheets
wbs.Add(wb); // collect workbooks
for (int i = 0; i < wss.Count; i++)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wss[i]); // release it
wss[i] = null; // null it
for (int i = 0; i < wbs.Count; i++)
wbs[i].Close(null, null, null);
System.Runtime.InteropServices.Marshal.ReleaseComObject(wbs[i]); // release it
wbs[i] = null; // null it
exc.Workbooks.Close(); // so you can close this
exc.Quit(); // so you can quit this
System.Runtime.InteropServices.Marshal.ReleaseComObject(exc); // release it
exc = null;
GC.Collect(); // this sets up the finalizers
GC.Collect(); //apparently this kills it
catch (Exception ex)
// deal with it fool!
I found this in the documentation on one of the COM Release functions:
// Note that COM objects that raise events within a .NET client require two Garbage Collector (GC)
// collections before they are released. This is caused by the reference cycle that occurs between
// COM objects and managed clients. If you need to explicitly release a COM object you should call
// the Collect method twice.
So I do a double GC on the main app object if I've setup any event handlers for it.
Normally not... but the problem is that all language specific char may not be read correctly. For exemple instead of ü i get | ... to solve that problem I have to decode the table (this is already done)
The problem is that some times I get tables that are already encoded correctly... in that case I don't need to decode the table...
Life is not short... the problem is only how you organize yourself
I'm trying to connect remotely from phone to pc. Currently I tested it in cradle mode. When I tried running my program (which is in the phone) it occured an error: Cannot find DbNetlib.dll. However, when I tried a pc to pc wireless connection (using an emulator) it works. It connects to the server just fine. Does anyone know how I can make my PDA phone connect to the server? I'm just copying the .exe file of my project file by the way.
i need to call a c# code in my java program. i followed the approach given in the codeproject link: http://www.codeproject.com/KB/cross-platform/javacsharp.aspx but there are some issues in generating netmodule , which is required to perform further steps. but it is giving an error
"csc /debug /t:module "bin\Debug\\HelloWorld.dll"" exited with code 9009 on using post build event command line.
E:\c#\getOLCont\getOLCont>csc /t:module form1.cs
the error is:
fatal error CS0009: Metadata file 'c:\Program Files\Reference
could not be opened -- 'File is corrupt.'
i have tried the command on different machines but there is same result.
HI, I want to iterate only those rows of excel sheet where the data have written, means if user has filled only first 15 rows then my loop should iterate to 15 only,hO wcan i do that Below is sample code which iterates up to 65536 rows,unnecessarily ,but the data are present only in first 15 or 18 rows. Please give me a solution or an idea
This is my sample code
Microsoft.Office.Interop.Excel.Application Excelobj = new Microsoft.Office.Interop.Excel.Application();
if (Excelobj == null)
MessageBox.Show("Excel couldn't be started", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);