title: Updating existing excel file while it is open
body: <p>I read a lot about how to communicate from C# to Excel and saw some good references.</p>
  
  <p>The thing is I'm looking for an easy way to update existing excel file while it is still open, using 
  the most advanced way (linq for example) and not OLEDB.</p>
  
  <p>This should be few lines of code describing how can I read current cell, update his value and take into consideration the file might not be exist, but if it does exist and open, it will just update the file without giving the notification the file is already exist. If the file doesn't exist it will create a new one. </p>
  
  <p>SO:
  1. connect to an excel file, check if it exist, if not create one<br>
  2. read from cell<br>
  3. update cell<br>
  4. do this while the excel sheet can be still open wild.  </p>
  
  <p>I already visited the following places:</p>
  
  <p><a href="http://social.msdn.microsoft.com/Forums/vstudio/en-US/ef11a193-54f3-407b-9374-9f5770fd9fd7/writing-to-excel-using-c" rel="nofollow noreferrer">http://social.msdn.microsoft.com/Forums/vstudio/en-US/ef11a193-54f3-407b-9374-9f5770fd9fd7/writing-to-excel-using-c</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5923589/updating-an-excel-document-programmatically">Updating an excel document programmatically</a></p>
  
  <p><a href="https://stackoverflow.com/questions/15894628/update-specific-cell-of-excel-file-using-oledb">Update specific cell of excel file using oledb</a></p>
  
  <p>I used the following code:</p>
  
  <pre><code>   if (File.Exists(@"C:\\temp\\test.xls"))
          {
              Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
              Microsoft.Office.Interop.Excel.Workbooks workBooks = excelApp.Workbooks;
              Microsoft.Office.Interop.Excel.Workbook workBook = workBooks.Open(@"C:\\temp\\test.xls");
              Microsoft.Office.Interop.Excel.Worksheet workSheet = workBook.Worksheets.get_Item(1);
              int nColumns = workSheet.UsedRange.Columns.Count;
              int nRows = workSheet.UsedRange.Rows.Count;
  
              for (int i = 2; i &lt; nRows; i++)
              {
                  workSheet.Columns["1","A"] = "test";
              }
  
              workBook.Save();
              workBook.Close();
          }
  </code></pre>