Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>First, I sincerely hope this isn't running on a server. </p> <p>Then, if your problem is that too many instances of Excel are created, a thought is "don't create an instance every single time". Instead of starting Excel every time AddDropDownToExcel is called, can you reuse the same instance? </p> <p>The problem you are having shows up regularly in Excel interop scenario; even though you are done and tell Excel to close, it "stays alive". It's usually caused by your app still holding a reference to a COM object that hasn't been disposed, preventing Excel from closing. This StackOverflow answer provides some pointers: <a href="https://stackoverflow.com/a/158752/114519">https://stackoverflow.com/a/158752/114519</a> </p> <p>In general, to avoid that problem, you want to follow the "one-dot" rule. For instance, in your code:</p> <pre><code>var workbook = application.Workbooks.Open(fileName); </code></pre> <p>will be a problem, because an "anonymous" wrapper for Workbooks is created, and will likely not be disposed properly. The "one-dot" rule would say "don't use more than one dot when working with Excel interop", in this case:</p> <pre><code>var workbooks = application.Workbooks; var workbook = workbooks.Open(fileName); </code></pre> <p>A totally different thought - instead of using Interop, can't you use OpenXML to generate your Excel file? I have never tried it to create drop downs, but if it supports it, it will be massively faster than Interop, and the type of problems you have won't happen.</p> <p>Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload