c# - The file name or path doesn't exist or used by other program while writing Excel file -
this question has answer here:
- create excel (.xls , .xlsx) file c# 38 answers
i trying create excel file , write data it. here code using.
using excel = microsoft.office.interop.excel; excel.application xlapp; excel.workbook xlworkbook; excel.worksheet xlworksheet; object misvalue = system.reflection.missing.value; xlapp = new excel.applicationclass(); xlworkbook = xlapp.workbooks.add(misvalue); xlworksheet = (excel.worksheet)xlworkbook.worksheets.get_item(1); xlworksheet.cells[1, 1] = "muneeb hassan soomro"; xlworkbook.saveas("csharp-excelwrite.xls",excel.xlfileformat.xlworkbooknormal,misvalue,misvalue,misvalue,misvalue,excel.xlsaveasaccessmode.xlexclusive,misvalue,misvalue,misvalue,misvalue,misvalue); //xlworkbook.saveas("csharp-excel.xls", excel.xlfileformat.xlworkbooknormal); xlworkbook.close(true, misvalue, misvalue); xlapp.quit();
i exception on xlworkbook.saveas()
call. says:
the file name or path doesn't exist or used other program
what doing wrong here?
so 1 of comments on answer got exception text (this information should have been included in question!)
the file name or path doesn't exist or used other program
the solution should simple: specify full path in saveas
call, not file name. how should excel know in folder should save file otherwise?
Comments
Post a Comment