4

Background: I am developing an excel Add-in using OfficeJS library. The addin is using the ReactJS components and Office Fabric UI. The Add-in is successfully created and using OfficeJS library we can bring the user selection to the Excel sheet.

Problem: The problem is that I want to get the event in OfficeJS to Save the sheet using the Excel Native capability i.e., once user clicks on Save then the Save Dialogue box will appear(as per Native excel behavior)and on that I want to invoke my ReactJS business rules(some functionalities). In order to do that I want to use Save event for the same in OfficeJS which should be triggered automatically.

Code Sample:

Office.initialize = () => {
    Excel.run(function (context) {
        var sheet = context.workbook.worksheets.getItem("Sheet1");             
        context.workbook.load(["save"]);                                                  
        context.sync().then(() => {
        context.workbook.save(Excel.SaveBehavior.prompt);
        //OR
        context.workbook.save(Excel.SaveBehavior.save);
        });
    }).catch(function(error) {
        console.log(error.debugInfo);
    });
}

Research: The above two functions which I have tried are from the Microsoft Documentation where it is mentioned as:

Workbook.save saves the workbook to persistent storage. The save method takes a single, optional saveBehavior parameter that can be one of the following values:

Excel.SaveBehavior.save (default): The file is saved without prompting the user to specify file name and save location. If the file has not been saved previously, it's saved to the default location. If the file has been saved previously, it's saved to the same location. Excel.SaveBehavior.prompt: If file has not been saved previously, the user will be prompted to specify file name and save location. If the file has been saved previously, it will be saved to the same location and the user will not be prompted.

System Configurations: I am using Windows 10, Excel 2016 Desktop and Office 365 Online version. I am using IE-10 and Google Chrome for Online version of Excel. Additionally I have checked the same using Windows-7 and Excel-2016 and same browsers.

Do let me know if the above functionality can be achieved?

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331

1 Answers1

1

Unfortunately, Office JS Excel API currently doesn't support onSaved event. one of the reasons was that Excel has an autosave feature, which triggers save action frequently. So we worry to provide onSaved event may fire too many event notifications to customers.

But I would suggest that you could submit the request and upvote this request at uservoice

Raymond Lu
  • 2,178
  • 1
  • 6
  • 19