Tuesday, 27 August 2013

cant able to save the excel file in c#

cant able to save the excel file in c#

here i am using excel sheet to save some data,and accessing that sheet by
using following code and perform some modification to the excel sheet,
after that try to save that file.but unable to save the file.Here is my
code
Application excel = new Application();
excel.Visible=true;
Workbook wb =
(Workbook)excel.Workbooks.Open(@"C:\Users\dnyanesh.wagh\Desktop\BookExcel1.xlsx");
Worksheet ws = (Worksheet)wb.Worksheets[1];
ws.Cells[1, 1] = "sagar";
ws.Cells[2, 1] = "sagar";
ws.Cells[3, 1] = "sagar";
wb.Save();
wb.close();
it is giving the error that "the file named 'BookExcel1.xlsx' already
exist in this location.you want to replace it." Then after that I change
the code to
Workbook wb =
(Workbook)excel.Workbooks.Open(@"C:\Users\dnyanesh.wagh\Desktop\BookExcel1.xlsx",0,
false, 5, "", "",
false, XlPlatform.xlWindows, "", true, false,
0, true, false, false););
it is giving again error saying "BookExcel1.xlsx is being modified by
user_name.open as read only".if click 'cancel' button then giving
exception at above line i.e."Exception from HRESULT: 0x800A03EC" also I
try as
wb.SaveAs(@"C:\Users\dnyanesh.wagh\Desktop\BookExcel1.xlsx");
wb.Close(true,null,null);
then also giving error.the above file showing the modifications. Can
anybody tell me how can I save the file with modifications.

No comments:

Post a Comment