I need to do the following:
-> open Excel file
-> change values of required cells
-> then save the file
right now I am doing this:
Excel.Application xlAppoutput = null;
Excel.Workbook xlWorkBookoutput = null;
Excel.Worksheet xlWorkSheetoutput = null;
Excel.Range rangeoutput = null;
try
{
xlAppoutput = new Excel.ApplicationClass();
xlWorkBookoutput = xlAppoutput.Workbooks.Open(@"D:\Askari9\output\myFile.xls", Type.Missing, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
xlWorkSheetoutput = (Excel.Worksheet)xlWorkBookoutput.Worksheets.get_Item(1);
rangeoutput = xlWorkSheetoutput.UsedRange;
//(rangeoutput.Cells[12, 3] as Excel.Range).Value2 = "new value";
xlWorkBookoutput.Close(true, null, null);
xlAppoutput.Quit();
releaseObject(xlWorkSheetoutput);
releaseObject(xlWorkBookoutput);
releaseObject(xlAppoutput);
}catch(Exception ex){
System.Console.Write(ex.StackTrace);
System.Console.Write("System could not successfully generate bill for House#" + Reader.GetValue(houseNoFieldIndexInDB).ToString()+"\n");
releaseObject(xlWorkSheetoutput);
releaseObject(xlWorkBookoutput);
releaseObject(xlAppoutput);
}
I get an exception on 'xlAppoutput.Quit();'
Can anyone please help me fix this? or tell me any other way of doing the same job (open excel file, change it then save it)