We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to know if spreadsheet has been modified?

Hi, I would like to know if there is a way to know if a spreadsheet is modified - such as if user wants to close the application, prompt the user to save spreadsheet if it has  been modified? 

Thank you.


4 Replies

AR Arulpriya Ramalingam Syncfusion Team January 21, 2020 08:52 AM UTC

Hi Chris, 
 
Thank you for using Syncfusion products. 
 
By default, the Spreadsheet for WinForms will popup a messagebox when the spreadsheet contents are modified to save the changes or not. The action can be manually invoked by using the FileClose command of Spreadsheet when the form is closing. Please make use of below code. 
 
Example code 
 
//Event subscription. 
this.FormClosing += Form1_FormClosing; 
 
//Event customization 
private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    spreadsheet.Commands.FileClose.Execute(this.spreadsheet); 
} 
 
Please get back to us, if you have any other queries. 
 
Regards, 
Arulpriya 



CH Chris January 21, 2020 01:46 PM UTC

Thank you... but is there a way to test to see if the spreadsheet is modified?  I want to create custom prompts, etc.


CH Chris January 21, 2020 01:47 PM UTC

Plus, if I click cancel in the "do you want to save this file" box, it still closes - how would I test that the user clicked Cancel to prevent closing?



AR Arulpriya Ramalingam Syncfusion Team January 22, 2020 10:19 AM UTC

Hi Chris, 
 
Thank you for the update. 
 
Thank you... but is there a way to test to see if the spreadsheet is modified?  I want to create custom prompts, etc. 
The Spreadsheet does not have any public property to check whether the sheet values are updated or changed. This can be achieved by retrieving the property value of IsCellModified through reflection. Please make use od below code and sample. 
 
Example code 
 
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) 
{ 
    PropertyInfo pi = spreadsheet.Workbook.GetType().GetProperty("IsCellModified", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 
 
    if (pi != null) 
        if (pi.GetValue(spreadsheet.Workbook as WorkbookImpl).ToString() == "True") 
        { 
            //Code to perform your actions. 
        } 
    //To execute the message box to save or cancel the action. 
    this.spreadsheet.Commands.FileClose.Execute(null); 
    if (Form.ActiveForm != null) 
        e.Cancel = true; 
    base.OnClosing(e); 
} 
Plus, if I click cancel in the "do you want to save this file" box, it still closes - how would I test that the user clicked Cancel to prevent closing? 
By default, the Cancel action of FileClose.Execute message box will restrict the form closing and we suspect that the use case might be occurred due to some other customization of executing the Save/Cancel MessageBox. Please refer to the below sample and let us know the code part that are missed in the project to replicate the issue at our end. So that, we could analyze further to provide a better solution at the earliest. 
 
 
 
Regards, 
Arulpriya 


Loader.
Live Chat Icon For mobile
Up arrow icon