Excel operation in .net

Jan 2 2013 1:18 PM
Hi,

We are developing one Application in c#.Net.
we are using Office2003 , VS 2010 and 4.0 Framework.
In My Application Excel files reading ,Writing and creating sheets.
we have problems in development.
1. At the time of App Reading Excel file. We are  trying to open another file (not reading file)  by manually then Automatically opening reading excel file along with manually opening excel file. how to prevent app reading excel file opening. we tried so many ways but we did not find solution.
2. to dispose the excel application object we are using Quit() method. this method  closing all the excel objects even manually opened excel files also. But we don't wants close manually opened excel files.

Can any one help us . to resolve this issues. this is very important to us.

this is our one method to read excel file

  public List<string> serviceCall()
  {
  List<string> returnString = new List<string>();
  Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
  Workbook xlWBook;
  Worksheet xlWSheet;
  Range xlRange;

  try
  {
  writer.WriteLine(" Step 1 --- Excel file reading started..........");
  xlWBook = xlApp.Workbooks.Open(@"E:\temp.xls", 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
  xlApp.Visible = false;
 
 
  xlWSheet = (Worksheet)xlWBook.Worksheets.get_Item("sheet one");
 
  xlRange = xlWSheet.UsedRange;

 
  for (int r = 1; r <= xlRange.Rows.Count; r++)
  {
 
  object value = (xlRange.Cells[r, 3] as Range).Value2;

  returnString.Add(value == null ? "" : value.ToString());

 
 

  }
 
 
  releaseObject(xlWSheet);

  xlWSheet = null;

  releaseObject(xlWBook);

  xlWBook = null;

  releaseObject(xlApp);

  }
  catch (Exception ex)
  {
 

  }
  finally
  {
  GC.Collect();
  GC.WaitForPendingFinalizers();
  }


  }

  return returnString;
  }

  private void releaseObject(object obj)
  {
  try
  {
  System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
  obj = null;
  }
  catch (Exception ex)
  {
  obj = null;
  }
  finally
  {
  GC.Collect();
  }
  }