|
-
July 3rd, 2011, 12:10 PM
#1
Open Excel file, change it and save it
I need to do the following:
-> open Excel file
-> change values of required cells
-> then save the file
right now I am doing this:
Code:
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)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|