Closing Excel Application Process in C# after Data Access -
i'm writing application in c# opens excel template file read/write operations. want when user closes application, excel application process has been closed, without saving excel file. see task manager after multiple runs of app.
i use code open excel file :
public excel.application excelapp = new excel.application(); public excel.workbook excelbook; excelbook = excelapp.workbooks.add(@"c:/pape.xltx");
and data access use code :
excel.worksheet excelsheet = (worksheet)(excelbook.worksheets[1]); excelsheet.displayrighttoleft = true; range rng; rng = excelsheet.get_range("c2"); rng.value2 = txtname.text;
i see similar questions in stackoverflow such this question , this, , test answers, doesn't works.
try this:
excelbook.close(0); excelapp.quit();
when closing work-book, have 3 optional parameters:
workbook.close savechanges, filename, routeworkbook
workbook.close(false)
or if doing late binding, easier use 0 workbook.close(0)
how i've done when automating closing of workbooks.
also went , looked documentation it, , found here: excel workbook close
thanks,
Comments
Post a Comment