I am using C# &amp; VS2013 and VSTO.  My code executes to perfection, but the one issue I have is that when I go to Task Manager and look at Details, Excel is still showing as running even after, I feel like I have properly cleaned up.  This is the syntax I use to cleanup and close all references to Excel.  Just the references to Excel &amp; VSTO, I left out the meat and gravy that does the leg work or this post would be to long.  Do I have something set-up improperly?  Why does Excel still show up in Task Manager?  namespace ReleaseExcel {   public partial class Form12 : Form12   {     public static Excel.Worksheet newSeet;     public static Excel._Worksheet currentsheet;     public static Excel._Workbook oWB;     public static Excel.Application xlApp;     public static Excel.Workbook xlWorkBook;     public static Excel.Worksheet xlWorkSheet;     public static Excel.Workbook activeworkbook;      public Form1()     {       InitializeComponents();     }     private void DoThis()     {         //Showing Declerations to Excel         xlApp = new Excel.Application();         xlWorkBook = xlApp.Workbooks.Add(misValue);         xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);          //Do some more stuff here          //Showing a few more Declerations to Excel         currentsheet = (Excel._Worksheet)(xlWorkBook.ActiveSheet);         Excel.Range last = currentsheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);          //Do a bit more stuff         ClearExcel();         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkSheet) != 0) { }         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(currentsheet) != 0) { }         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook) != 0) { }         while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) != 0) { }     }     private static void ClearExcel()     {         GC.Collect();         GC.WaitForPendingFinalizers();     }         } }   EDIT I added in GC.Collect() &amp; GC.WaitForPendingFinalizers() but now my syntax hangs on   while (System.Runtime.InteropServices.Marshal.ReleaseComObject(xlWorkBook) != 0) { }   It has been sitting on this line for about 5 minutes now, what causes the freeze?  EDIT # 2 Still no such luck.  This is code  namespace ReleaseExcel {    public partial class Form12 : Form12   {     public static Excel.Worksheet newSeet;     public static Excel._Worksheet currentsheet;     public static Excel._Workbook oWB;     public static Excel.Application xlApp;     public static Excel.Workbook xlWorkBook;     public static Excel.Worksheet xlWorkSheet;     public static Excel.Workbook activeworkbook;      public Form1()     {       InitializeComponents();     }      public void btnPush_Click(object sender, EventArgs e)     {         DoThis();         GC.Collect();         GC.WaitForPendingFinalizers();     }     private void DoThis()     {       //Showing Declerations to Excel       xlApp = new Excel.Application();       xlWorkBook = xlApp.Workbooks.Add(misValue);       xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);        //Do some more stuff here        //Showing a few more Declerations to Excel       currentsheet = (Excel._Worksheet)(xlWorkBook.ActiveSheet);       Excel.Range last = currentsheet.Cells.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing);      }   } }
10586
I'm using the Excel interop in C# (ApplicationClass) and have placed the following code in my finally clause:  while (System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet) != 0) { } excelSheet = null; GC.Collect(); GC.WaitForPendingFinalizers();   Although this kind of works, the Excel.exe process is still in the background even after I close Excel. It is only released once my application is manually closed.  What am I doing wrong, or is there an alternative to ensure interop objects are properly disposed of?
97506
We are displaying an excel sheet via excel web access web part on a sharepoint page. There is only 1 excel sheet containing 2 charts.  This appears like a normal excel doc with grid lines, 2 charts and tabs below for sheets. How do I remove the gridlines, row numbers, column headers, scroll bars and sheets tab from the excel web access webpart for better look?
80463
One thing that annoys me when debugging programs in Visual Studio (2005 in my case) is that when I use "step over" (by pressing F10) to execute to the next line of code, I often end up reaching that particular line of code in a totally different thread than the one I was looking at. This means that all the context of what I was doing was lost.  How do I work around this?  If this is possible to do in later versions of Visual Studio, I'd like to hear about it as well.  Setting a breakpoint on the next line of code which has a conditional to only break for this thread is not the answer I'm looking for since it is way too much work to be useful for me :)
26253
Whenever you copy a cell or a range of cells in Excel (my version is 2010 on Windows 7), and then do something else like insert new sheet row or simply edit another cell, Excel removes the clipboard data. For me this seems to me so utterly stupid and it's very frustrating (probably it has some logic behind it like preserving references or something like that, but I don't think it would be rocket science to make it work like any other program that has Copy-Paste available).   The only workaround is to use the Office clipboard, but I don't want to (uses space on the screen and it's a lot less comfortable than CTRL+V) and I don't think I should be forced to use it.  Here's a reference to some posts also complaining about this problem:      Is there any way I can force Excel to keep my data into the clipboard until I decide I don't need it no more instead of it, without using the annoying (to me) Office clipboard? Maybe using the Windows clipboard.  Or at least you could explain to me why this is happening (I know this is normal behavior, but why?)
62585
Given the following example, why do I have to explicitly use the statement b-&gt;A::DoSomething() rather than just b-&gt;DoSomething()?  Shouldn't the compiler's overload resolution figure out which method I'm talking about?  I'm using Microsoft VS 2005. (Note: using virtual doesn't help in this case.)  class A {   public:     int DoSomething() {return 0;}; };  class B : public A {   public:     int DoSomething(int x) {return 1;}; };  int main() {   B* b = new B();   b-&gt;A::DoSomething();    //Why this?   //b-&gt;DoSomething();    //Why not this? (Gives compiler error.)   delete b;   return 0; }
37131
I don't know if it's legit at StackOverflow to post your own answer to a question, but I saw nobody had asked this already.  I went looking for a C# Glob and didn't find one, so I wrote one that others might find useful.
17191
I'm providing internal support and one of our users has managed to put a password on an excel file by accident, I've done the proper checks to make sure that the user should have access to the document and now want to know what the recommendation for removing a password from an Excel document.  For what its worth, the password appears after Excel opens but before you can see any data in excel.
119531
I am trying to view the file name that I am working on in the Excel spreadsheet of interest using a formula. For example if the file was called workbook1.xlsx then I would want cell A1 to show "workbook1.xlsx"   The formula that Microsoft's help site gives doesn't work:      =MID(CELL("filename"),SEARCH("[",CELL("filename"))+1, SEARCH("]",CELL("filename"))-SEARCH("[",CELL("filename"))-1)
110566
In Visual Studio, I can select the "Treat warnings as errors" option to prevent my code from compiling if there are any warnings. Our team uses this option, but there are two warnings we would like to keep as warnings.   There is an option to suppress warnings, but we DO want them to show up as warnings, so that won't work.  It appears that the only way to get the behavior we want is to enter a list of every C# warning number into the "Specific warnings" text box, except for the two we want treated as warnings.  Besides the maintenance headache, the biggest disadvantage to this approach is that a few warnings do not have numbers, so they can't be referenced explicitly. For example, "Could not resolve this reference. Could not locate assembly 'Data....'"  Does anyone know of a better way to do this?    Clarifying for those who don't see immediately why this is useful. Think about how most warnings work. They tell you something is a little off in the code you just wrote. It takes about 10 seconds to fix them, and that keeps the code base cleaner.  The "Obsolete" warning is very different from this. Sometimes fixing it means just consuming a new method signature. But if an entire class is obsolete, and you have usage of it scattered through hundreds of thousands of lines of code, it could take weeks or more to fix. You don't want the build to be broken for that long, but you definitely DO want to see a warning about it. This isn't just a hypothetical case--this has happened to us.  Literal "#warning" warnings are also unique. I often want to check it in, but I don't want to break the build.
5676
How can I create an Excel spreadsheet with C# without requiring Excel to be installed on the machine that's running the code?
52358
I'm writing an application that can be started either as a standard WinForms app or in unattended mode from the command-line. The application was built using the VS 2k5 standard WinForms template.  When the application is executed from the command-line, I want it to output information that can be captured by the script executing the application. When I do this directly from Console.WriteLine(), the output does not appear, although it can be captured by piping to a file.  On the other hand, I can force the application to pop up a second console by doing a P/Invoke on AllocConsole() from kernel32. This is not what I want, though. I want the output to appear in the same window the application was called from.  This is the salient code that allows me to pop up a console from the command line:  &lt;STAThread()&gt; Public Shared Sub Main()      If My.Application.CommandLineArgs.Count = 0 Then         Dim frm As New ISECMMParamUtilForm()         frm.ShowDialog()     Else         Try             ConsoleControl.AllocConsole()             Dim exMan As New UnattendedExecutionManager(ConvertArgs())             IsInConsoleMode = True             OutputMessage("Application started.")             If Not exMan.SetSettings() Then                 OutputMessage("Execution failed.")             End If         Catch ex As Exception             Console.WriteLine(ex.ToString())         Finally             ConsoleControl.FreeConsole()         End Try      End If  End Sub  Public Shared Sub OutputMessage(ByVal msg As String, Optional ByVal isError As Boolean = False)     Trace.WriteLine(msg)     If IsInConsoleMode Then         Console.WriteLine(msg)     End If      If isError Then         EventLog.WriteEntry("ISE CMM Param Util", msg, EventLogEntryType.Error)     Else         EventLog.WriteEntry("ISE CMM Param Util", msg, EventLogEntryType.Information)     End If  End Sub
7668
Is there a way to do a particular task manually, generate the code for it automatically and update that code to do some task repeatedly?  I'm looking for something like record macro functionality that's available in MS Excel.
111110
I'm a bit confused as to how to get two method to call each other (i.e., have A() call B() and B() call A()). It seems that F# only 'sees' the method after it's been encountered in code, so if it hasn't, it just says value or constructor has not been defined.  Am I missing something very basic here?
29507
I have been running  over some C# code, and it keeps reporting that my using directives should be inside the namespace.  Is there a technical reason for putting the using directives inside instead of outside the namespace?
8886
I've seen this done in Borland's  environment, but I'm not sure how to go about it for a C# application I'm working on. Are there best practices or gotchas to look out for?
60649
I have an Excel file that want to update and save automatically with out having to open it or manually interact with.  Manually, I open the file up and hit data refresh which goes and does a SQL query and then hit F9 for the formulas to update and then I just close/save.    (I then would mail the file out to people using a perl script or use SAS JMP to run some numbers/charts and also mail them out.  Basically I need to script some things which require the XLS file to be updated.)
25623
The code snippet below changes the data validation state of a cell and runs when the Excel-2003 worksheet is unprotected. However, when I protect the work sheet the macro doesn't run and raises a run-time error     Run-time error '-2147417848 (80010108)':      Method 'Add' of object 'Validation' failed   I have tried wrapping the code with   Me.unprotect ... Me.protect   But this does not work properly.  So, how can I modify the code below to work (ie have the code modify the unlocked cell's validation) when the sheet is protected without the above run-time error?  Update  My original work book is an Excel 2003. I tested @ solution in Excel 2007 with the following definition for Workbook_Open  Sub WorkBook_Open()     Me.Worksheets("MainTable").Protect  contents:=True, userinterfaceonly:=True  End Sub   The code still fails with the following run-time error when the worksheet is protected     Run-time error '1004':   Application-defined or object-defined error   Thanks, Azim    Code Snippet  'cell to add drop down validation list' dim myNamedRange as String dim modifyCell as Range  modifyCell = ActiveCell.Offset(0,1)    ' set list values based on some conditions not defined for brevitity' If myCondition then    myNamedRange = "range1" Else    myNamedRange = "range2" End If  With modifyCell.Validation    .Delete     'Run time error occurs on the next line'    .Add Type:=xlValidateList, AlertStyle:=xlValidAltertStop, _         Operator:=xlBetween, Formula1:="=" &amp; myNamedRange     ...     ' skipping more property setting code '    ... End With