Excel don’t save on closing

oWB.BeforeSave += new Microsoft.Office.Interop.Excel.WorkbookEvents_BeforeSaveEventHandler(oWB_BeforeSave);

 

void oWB_BeforeSave(bool SaveAsUI, ref bool Cancel){

//SaveAsUI = false;

Cancel = true;

throw new Exception(“The method or operation is not implemented”);

}

Anuncios

Save as PDF

string pdfName = directory + @”\” + filenameWithExtension;

oWB.ExportAsFixedFormat(Excel.XlFixedFormatType.xlTypePDF, pdfName, Type.Missing, true, true, Type.Missing, Type.Missing, false, Type.Missing);

Exit Excel Application Process

excelBook.Close();

excelApp.Quit();   //Important: When you forget this, Excel keeps running in the background.