We generate a bunch of reports to Excel spreadsheets using EPPlus.
Typically the code goes something like this:
var workbookFile = new FileInfo(reportFile);
using (var excel = new ExcelPackage(workbookFile))
{
var wb = excel.Workbook;
var ws = wb.GetCleanWorksheet("Report");
ws.Select();
// write data to sheet
ws.Cells[1, 1].Value = "foo";
excel.Save();
}
When the user opens the spreadsheet, everything looks fine. When they try to close the spreadsheet without having made any changes, Excel will ask them whether they want to save their changes. This isn't too big a deal but it's annoying and slightly worrying.
I've opened the spreadsheets in the OpenXML SDK Productivity Tool and they pass validation in that.
This behavior occurs when something in the file has changed. Many times the user doesn't realize there are elements in the file that have been updated or calculated. Here are some examples of common scenarios: There is a volatile function used in the file.
Summary. In Microsoft Excel, you can create a Microsoft Visual Basic for Applications (VBA) macro that suppresses the Save Changes prompt when you close a workbook. This can be done either by specifying the state of the workbook Saved property, or by suppressing all alerts for the workbook.
If you click Save and you have previously saved your file, Excel saves your file in the same location you previously saved it, using the file name and file type you previously used. If you click Don't Save, Excel exits without saving. If you click Cancel, Excel returns to the workbook and you can continue editing.
Here's an response to a similar question answered by Microsoft support at http://support.microsoft.com/kb/213428 "To force a workbook to close without saving any changes, type the following code in a Visual Basic module of that workbook:
Sub Auto_Close()
ThisWorkbook.Saved = True
End Sub
Because the Saved property is set to True, Excel responds as though the workbook has already been saved and no changes have occurred since that last save."
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With