using Excel = Microsoft.Office.Interop.Excel; private void closeWorkbook() { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook = excelApp.Workbooks.Open("path/to/workbook.xls", ReadOnly: false); workbook.Close(SaveChanges: true); excelApp.Quit(); }
using Excel = Microsoft.Office.Interop.Excel; private void closeWorkBookWithoutSave() { Excel.Application excelApp = new Excel.Application(); Excel.Workbook workbook = excelApp.Workbooks.Open("path/to/workbook.xlsx"); workbook.Close(SaveChanges: false); excelApp.Quit(); }This code example shows how to close an Excel workbook without saving any changes made to the workbook. The workbook is opened using Excel.Application and Excel.Workbook objects. The workbook is then closed without saving changes using the workbook.Close(SaveChanges: false) method while the application is closed using the excelApp.Quit() method. Package Library: Microsoft.Office.Interop.Excel (It provides types for working with the Excel COM (Component Object Model) object model. These types provide an efficient and simple way to automate Microsoft Excel functionalities, which is why it is used in the above examples).