<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://involvenevolve.com/rss/xslt"?>
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title>Sudarshan's Blog</title>
    <link>http://involvenevolve.com/</link>
    <description>My Thoughts, Findings &amp; Experiences</description>
    <generator>Articulate, blogging built on Umbraco</generator>
    <item>
      <guid isPermaLink="false">1107</guid>
      <link>http://involvenevolve.com/archive/excel-application-object-unexpected-behavior/</link>
      <category>.NET</category>
      <category>MS-Excel</category>
      <title>Excel Application Object – Unexpected Behavior</title>
      <description>&lt;p align="justify"&gt;In my last article ‘’, I have explained why we choose to use Excel Application object for excel automation and its disposing mechanism. But, while testing we observed following unexpected behavior:&lt;/p&gt;
&lt;p&gt;If we start processing multiple Excel files through windows service (like 25 to 50):&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;For few files, it threw exception related to COM Interop. The exception does not have any details and it only says ‘&lt;strong&gt;File can be accessed&lt;/strong&gt;’ even though file exists at correct location.&lt;/li&gt;
&lt;li&gt;For few files, it starts processing excel file. But the file processing never ends and its associated Excel process was alive too. (You can see ‘Excel’ process in ‘Task Manager’)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;There is no solution for above 2 issues (or at least we are not able to find any yet).&lt;/p&gt;
&lt;p&gt;So, beware while using Excel Application object in your application!&lt;/p&gt;
&lt;p&gt;P.S.: Because of unreliable behavior of Excel Application Objet, we are thinking of using some other third party solution for Excel automation.&lt;/p&gt;</description>
      <pubDate>Sun, 28 Aug 2011 09:35:00 Z</pubDate>
      <a10:updated>2011-08-28T09:35:00Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1106</guid>
      <link>http://involvenevolve.com/archive/excel-application-object-expects-desktop-folder-under-certain-paths/</link>
      <category>.NET</category>
      <category>MS-Excel</category>
      <title>Excel Application Object–Expects ‘Desktop’ folder under certain paths</title>
      <description>&lt;p align="justify"&gt;In my last article ‘’, I have explained why we choose to use Excel Application object for excel automation and its disposing mechanism. But, while testing we were getting following exception:&lt;/p&gt;
&lt;p&gt;Microsoft Excel cannot access the file '&amp;lt;file path&amp;gt;'. There are several possible reasons:&lt;/p&gt;
&lt;p&gt;• The file name or path does not exist.&lt;br /&gt;• The file is being used by another program.&lt;br /&gt;• The workbook you are trying to save has the same name as a currently open workbook.:    at Microsoft.Office.Interop.Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru, Object Local, Object CorruptLoad)&lt;/p&gt;
&lt;p&gt;But, file exists at that location.&lt;/p&gt;
&lt;p&gt;After spending hours, I am able to find solution for this weird issue.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Basically solution is to create ‘&lt;u&gt;Desktop&lt;/u&gt;’ folder under following paths on your machine&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;If your machine is 64-bit then&lt;br /&gt;- &lt;strong&gt;C:\Windows\SysWOW64\config\systemprofile&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If your machine is 32-bit then&lt;br /&gt;- &lt;strong&gt;C:\Windows\System32\config\systemprofile&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;My machine is 64-bit and I was already having ‘Desktop’ folder under ‘C:\Windows\SysWOW64\config\systemprofile’, but still it was not working.&lt;br /&gt;Just to try out I created ‘Desktop’ folder under ‘C:\Windows\System32\config\systemprofile’ (which was not exist) on my machine.&lt;/p&gt;
&lt;p&gt;And Bingo! Problem is solved. Exception went away and it is updating excel file correctly.&lt;/p&gt;
&lt;p&gt;Really strange but it worked!&lt;/p&gt;
&lt;p&gt;Looks like it creates some temporary file under ‘Desktop’ folder. But not too sure. Also it has something to do with under which user credentials it runs the windows service and excel application object.&lt;/p&gt;
&lt;p&gt;Note: Paths may vary on your machine depending on where ‘windows’ folder reside.&lt;/p&gt;
&lt;p&gt;I got idea for this solution from following 2 articles:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91?prof=required"&gt;http://social.msdn.microsoft.com/Forums/en-US/innovateonoffice/thread/b81a3c4e-62db-488b-af06-44421818ef91?prof=required&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Another solution: &lt;/strong&gt;(but this requires registry changes – which is not preferred to do it on production machine)&lt;br /&gt;&lt;a href="http://social.technet.microsoft.com/Forums/en-US/office2007deploymentcompatibility/thread/334c9f30-4e27-4904-9e71-abfc65975e23"&gt;http://social.technet.microsoft.com/Forums/en-US/office2007deploymentcompatibility/thread/334c9f30-4e27-4904-9e71-abfc65975e23&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Happy Programming!&lt;/p&gt;</description>
      <pubDate>Tue, 16 Aug 2011 06:25:00 Z</pubDate>
      <a10:updated>2011-08-16T06:25:00Z</a10:updated>
    </item>
    <item>
      <guid isPermaLink="false">1105</guid>
      <link>http://involvenevolve.com/archive/disposing-excel-application-object-correctly/</link>
      <category>.NET</category>
      <category>MS-Excel</category>
      <title>Disposing Excel Application object correctly</title>
      <description>&lt;p align="justify"&gt;On one of our recent project, we need to process lots of Excel files in windows service. Basic requirement was: we need to read excel file from specific folders, perform some operations, do additional calculations on data which we read from excel file and then write some additional data to existing excel file.&lt;/p&gt;
&lt;p align="justify"&gt;We started with using OLEDB as first and safe choice. But issue with OLEDB is, you cannot alter existing file structure. That means in our case we cannot add new columns to the existing excel file. So, we left OLEDB option.&lt;/p&gt;
&lt;p align="justify"&gt;Now, the only solution available is to use &lt;strong&gt;Excel Application&lt;/strong&gt; object which is part of Office Interop assemblies. Using this you can modify existing Excel files.&lt;/p&gt;
&lt;p align="justify"&gt;But, issue with this is: even though you execute code ‘Quit()’ method on Excel Application object, .Net does not dispose that Excel Application object. It will remain there in memory until you close your application. In our application, we are handling excel processing through windows service, so if we process 10 files then 10 excel objects will be created and they will reside in the memory. One can see those objects in Task Manager. Those objects will remain there until we stop Windows Service which creates these objects.&lt;/p&gt;
&lt;p align="justify"&gt;This is scary because we can’t stop Windows Service. If we don’t stop Windows Service then Excel objects will pile in the memory and at some point application will throw insufficient memory exception.&lt;/p&gt;
&lt;p align="justify"&gt;Another thing that surprised us is Microsoft suggests not to use Office objects in Automation. Here is what they say “&lt;em&gt;&lt;u&gt;Developers can use Automation in Microsoft Office to build custom solutions that use the capabilities and the features that are built into the Office product. Although such programmatic development can be implemented on a client system with relative ease, a number of complications can occur if Automation takes place from server-side code such as Microsoft Active Server Pages (ASP), ASP.NET, DCOM, or a Windows NT service.&lt;/u&gt;&lt;/em&gt;” in article &lt;a href="http://support.microsoft.com/kb/257757"&gt;http://support.microsoft.com/kb/257757&lt;/a&gt;&lt;/p&gt;
&lt;p align="justify"&gt;But for us using Excel Application object is the only option, so finally we come with following solution to dispose Excel Application object:&lt;/p&gt;
&lt;p align="justify"&gt; &lt;/p&gt;
&lt;div id="codeSnippetWrapper"&gt;
&lt;div id="codeSnippet" style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum1" style="color: #606060;"&gt;   1:&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;bool&lt;/span&gt; UpdateExcelFile(&lt;span style="color: #0000ff;"&gt;string&lt;/span&gt; filePath)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum2" style="color: #606060;"&gt;   2:&lt;/span&gt; {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum3" style="color: #606060;"&gt;   3:&lt;/span&gt;     Workbook workbook = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum4" style="color: #606060;"&gt;   4:&lt;/span&gt;     Worksheet worksheet = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum5" style="color: #606060;"&gt;   5:&lt;/span&gt;     Range worksheetCells = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum6" style="color: #606060;"&gt;   6:&lt;/span&gt;     Range usedRange = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum7" style="color: #606060;"&gt;   7:&lt;/span&gt;     Range cells = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum8" style="color: #606060;"&gt;   8:&lt;/span&gt;     Range columns = &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum9" style="color: #606060;"&gt;   9:&lt;/span&gt;  &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum10" style="color: #606060;"&gt;  10:&lt;/span&gt;     var excelApplication = &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; Application { DisplayAlerts = &lt;span style="color: #0000ff;"&gt;false&lt;/span&gt; };&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum11" style="color: #606060;"&gt;  11:&lt;/span&gt;     &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum12" style="color: #606060;"&gt;  12:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;try&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum13" style="color: #606060;"&gt;  13:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum14" style="color: #606060;"&gt;  14:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (!File.Exists(filePath))&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum15" style="color: #606060;"&gt;  15:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; ApplicationException(&lt;span style="color: #006080;"&gt;"File does not exists"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum16" style="color: #606060;"&gt;  16:&lt;/span&gt;  &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum17" style="color: #606060;"&gt;  17:&lt;/span&gt;         workbook = Open(excelApplication, filePath);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum18" style="color: #606060;"&gt;  18:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (workbook == &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum19" style="color: #606060;"&gt;  19:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;throw&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;new&lt;/span&gt; ApplicationException(&lt;span style="color: #006080;"&gt;"File cannot be opened"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum20" style="color: #606060;"&gt;  20:&lt;/span&gt;  &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum21" style="color: #606060;"&gt;  21:&lt;/span&gt;         var sheetIndex = GetSheetIndex(workbook, &lt;span style="color: #006080;"&gt;"SOV INPUT"&lt;/span&gt;);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum22" style="color: #606060;"&gt;  22:&lt;/span&gt;         worksheet = workbook.Sheets[sheetIndex];&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum23" style="color: #606060;"&gt;  23:&lt;/span&gt;         worksheetCells = worksheet.Cells;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum24" style="color: #606060;"&gt;  24:&lt;/span&gt;         usedRange = worksheet.UsedRange;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum25" style="color: #606060;"&gt;  25:&lt;/span&gt;         cells = usedRange.Cells;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum26" style="color: #606060;"&gt;  26:&lt;/span&gt;         columns = cells.Columns;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum27" style="color: #606060;"&gt;  27:&lt;/span&gt;  &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum28" style="color: #606060;"&gt;  28:&lt;/span&gt;         &lt;span style="color: #008000;"&gt;// Perform file operations like adding new columns, &lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum29" style="color: #606060;"&gt;  29:&lt;/span&gt;         &lt;span style="color: #008000;"&gt;// set values for new columns&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum30" style="color: #606060;"&gt;  30:&lt;/span&gt;         &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum31" style="color: #606060;"&gt;  31:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;true&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum32" style="color: #606060;"&gt;  32:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum33" style="color: #606060;"&gt;  33:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;catch&lt;/span&gt; (Exception ex)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum34" style="color: #606060;"&gt;  34:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum35" style="color: #606060;"&gt;  35:&lt;/span&gt;         Logger.ErrorFormat(&lt;span style="color: #006080;"&gt;"Error occurred while updating excel file {0} {1} : {2}"&lt;/span&gt;, filePath, ex.Message, ex.StackTrace);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum36" style="color: #606060;"&gt;  36:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;false&lt;/span&gt;;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum37" style="color: #606060;"&gt;  37:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum38" style="color: #606060;"&gt;  38:&lt;/span&gt;     &lt;span style="color: #0000ff;"&gt;finally&lt;/span&gt;&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum39" style="color: #606060;"&gt;  39:&lt;/span&gt;     {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum40" style="color: #606060;"&gt;  40:&lt;/span&gt;         GC.Collect();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum41" style="color: #606060;"&gt;  41:&lt;/span&gt;         GC.WaitForPendingFinalizers();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum42" style="color: #606060;"&gt;  42:&lt;/span&gt;         &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (workbook != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum43" style="color: #606060;"&gt;  43:&lt;/span&gt;         {&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum44" style="color: #606060;"&gt;  44:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (columns != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;) Marshal.ReleaseComObject(columns);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum45" style="color: #606060;"&gt;  45:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (cells != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;) Marshal.ReleaseComObject(cells);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum46" style="color: #606060;"&gt;  46:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (usedRange != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;) Marshal.ReleaseComObject(usedRange);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum47" style="color: #606060;"&gt;  47:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (worksheetCells != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;) Marshal.ReleaseComObject(worksheetCells);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum48" style="color: #606060;"&gt;  48:&lt;/span&gt;             &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt; (worksheet != &lt;span style="color: #0000ff;"&gt;null&lt;/span&gt;) Marshal.FinalReleaseComObject(worksheet);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum49" style="color: #606060;"&gt;  49:&lt;/span&gt;             workbook.Close();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum50" style="color: #606060;"&gt;  50:&lt;/span&gt;             Marshal.FinalReleaseComObject(workbook);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum51" style="color: #606060;"&gt;  51:&lt;/span&gt;         }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum52" style="color: #606060;"&gt;  52:&lt;/span&gt;  &lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum53" style="color: #606060;"&gt;  53:&lt;/span&gt;         excelApplication.Quit();&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum54" style="color: #606060;"&gt;  54:&lt;/span&gt;         Marshal.FinalReleaseComObject(excelApplication);&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum55" style="color: #606060;"&gt;  55:&lt;/span&gt;     }&lt;/pre&gt;
&lt;!--CRLF--&gt;
&lt;pre style="font-size: 8pt; overflow: visible; font-family: 'Courier New', courier, monospace; width: 100%; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; background-color: #f4f4f4; border-style: none; padding: 0px;"&gt;&lt;span id="lnum56" style="color: #606060;"&gt;  56:&lt;/span&gt; }&lt;/pre&gt;
&lt;!--CRLF--&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p align="justify"&gt; &lt;/p&gt;
&lt;p align="justify"&gt;As shown in solution: (Check ‘finally’ section)&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div&gt;You need to explicitly release reference for COM objects that you have created like&lt;/div&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;div&gt;Workbook&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Worksheet&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div&gt;Worksheet cells&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p align="justify"&gt;Only then ‘Quit()’ method on Excel Application object will dispose Excel Application object immediately.&lt;/p&gt;
&lt;p align="justify"&gt;Now, we can use Excel Application object safely within Windows Service. Thank you to my team member Selva for doing research on this.&lt;/p&gt;
&lt;p align="justify"&gt;Happy Programming!&lt;/p&gt;</description>
      <pubDate>Mon, 15 Aug 2011 07:46:00 Z</pubDate>
      <a10:updated>2011-08-15T07:46:00Z</a10:updated>
    </item>
  </channel>
</rss>