This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Excel add-ins support undo behavior. This preserves both actions performed by Excel JavaScript APIs and actions performed by the user in Excel. These actions are saved in theundo stack for an individual user, allowing the user to step back through their actions when desired.
Note
The features described in this article are currently available only in public preview. To use this feature, you must use the preview version of the Office JavaScript API library from theOffice.js content delivery network (CDN). Thetype definition file for TypeScript compilation and IntelliSense is found at the CDN andDefinitelyTyped. You can install these types withnpm install --save-dev @types/office-js-preview
.For more information on our upcoming APIs, please visitExcel JavaScript API requirement sets. To use this feature, you must also join theMicrosoft 365 Insider Program and download the latest build of Excel.
The Excel JavaScript API also supports undo grouping. This allows you to group multiple API calls into a single undoable action for your add-in user. For example, if your add-in needs to make several different updates across multiple worksheets in response to a single user command, you can wrap all those updates in a single group. This is done with themergeUndoGroup
property provided to theExcel.run
function.
If an API within the group doesn't offer undo support, theUndoNotSupported
error is thrown to let you know that the operation can’t be grouped. Your add-in should gracefully handle this error and present a reasonable message to the user.
The following code sample shows how to merge multiple actions withmergeUndoGroup
set totrue
.
Important
Ensure that all grouped API calls support undo to avoid errors. SeeUnsupported APIs for more information.
await Excel.run({ mergeUndoGroup: true }, async (context) => { const sheet = context.workbook.worksheets.getActiveWorksheet(); let range = sheet.getRange("A1"); range.values = [["123"]]; await context.sync(); range = sheet.getRange("B2"); range.values = [["456"]]; await context.sync(); });
Most Excel JavaScript APIs do support undo actions. However, see the following table for a list of APIs that do not support undo behavior.
Tip
If you call an unsupported API in your add-in, the user’s undo stack is cleared starting from that API call, and a user cannot undo actions past that point.
API | Supported in Excel on the web | Supported in Excel on Windows and Excel on Mac | Notes |
---|---|---|---|
AllowEditRange.address | No | No | None |
AllowEditRange.delete | No | No | None |
AllowEditRange.pauseProtection | No | No | None |
AllowEditRange.setPassword | No | No | None |
AllowEditRange.title | No | No | None |
AllowEditRangeCollection.add | No | No | None |
AllowEditRangeCollection.pauseProtection | No | No | None |
Chart.categoryLabelLevel | No | No | None |
Chart.seriesNameLevel | No | No | None |
ChartPivotOptions.showAxisFieldButtons | No | Yes | None |
ChartPivotOptions.showLegendFieldButtons | No | Yes | None |
ChartPivotOptions.showReportFilterFieldButtons | No | Yes | None |
ChartPivotOptions.showValueFieldButtons | No | Yes | None |
ChartTrendlineLabel.formula | No | Yes | None |
DataConnectionCollection.refreshAll | No | No | None |
DocumentProperties.author | No | Yes | None |
DocumentProperties.category | No | Yes | None |
DocumentProperties.comments | No | Yes | None |
DocumentProperties.company | No | Yes | None |
DocumentProperties.keywords | No | Yes | None |
DocumentProperties.manager | No | Yes | None |
DocumentProperties.revisionNumber | No | Yes | None |
DocumentProperties.subject | No | Yes | None |
DocumentProperties.title | No | Yes | None |
LinkedWorkbook.refresh | No | No | None |
LinkedWorkbookCollection.refreshAll | No | No | None |
NamedItem.comment | No | Yes | None |
PivotTableStyle.delete | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
PivotTableStyle.duplicate | No | Yes | None |
PivotTableStyle.name | No | Yes | None |
PivotTableStyleCollection.add | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
PivotTableStyleCollection.setDefault | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
Query.delete | No | Yes | API supports undo in Excel on Windows and Mac but doesn't support redo. |
Query.refresh | No | Yes | API supports undo Excel on Windows and Mac but doesn't support redo. |
QueryCollection.refreshAll | No | Yes | API supports undo Excel on Windows and Mac but doesn't support redo. |
Slicer.name | No | Yes | None |
Slicer.nameInFormula | No | Yes | None |
SlicerStyle.delete | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
SlicerStyle.duplicate | No | Yes | None |
SlicerStyle.name | No | Yes | None |
SlicerStyleCollection.add | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
SlicerStyleCollection.setDefault | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
Style.addIndent | No | Yes | None |
Style.autoIndent | No | Yes | None |
Style.formulaHidden | No | Yes | None |
Style.horizontalAlignment | No | Yes | None |
Style.includeAlignment | No | Yes | None |
Style.includeBorder | No | Yes | None |
Style.includeFont | No | Yes | None |
Style.includeNumber | No | Yes | None |
Style.includePatterns | No | Yes | None |
Style.includeProtection | No | Yes | None |
Style.indentLevel | No | Yes | None |
Style.locked | No | Yes | None |
Style.numberFormat | No | Yes | None |
Style.numberFormatLocal | No | Yes | None |
Style.orientation | No | Yes | None |
Style.readingOrder | No | Yes | None |
Style.shrinkToFit | No | Yes | None |
Style.textOrientation | No | Yes | None |
Style.verticalAlignment | No | Yes | None |
Style.wrapText | No | Yes | None |
TableStyle.delete | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
TableStyle.duplicate | No | Yes | None |
TableStyle.name | No | Yes | None |
TableStyleCollection.add | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
TableStyleCollection.setDefault | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
TimelineStyle.delete | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
TimelineStyle.duplicate | No | Yes | None |
TimelineStyle.name | No | Yes | None |
TimelineStyleCollection.add | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
TimelineStyleCollection.setDefault | No | Yes | API doesnot support co-authoring undo in Excel on Windows and Mac. |
Workbook.close | No | No | None |
Workbook.insertWorksheetsFromBase64 | No | No | None |
Workbook.save | No | No | None |
WorkbookProtection.protect | No | No | None |
WorkbookProtection.unprotect | No | No | None |
Worksheet.copy | No | No | None |
Worksheet.delete | No | No | None |
Worksheet.name | Yes | No | None |
Worksheet.standardWidth | No | Yes | None |
Worksheet.position | Yes | No | None |
Worksheet.visibility | Yes | No | None |
WorksheetCollection.addFromBase64 | No | No | None |
WorksheetProtection.pauseProtection | No | No | None |
WorksheetProtection.protect | No | No | None |
WorksheetProtection.resumeProtection | No | No | None |
WorksheetProtection.setPassword | No | No | None |
WorksheetProtection.unprotect | No | No | None |
WorksheetProtection.updateOptions | No | No | None |
Was this page helpful?
Was this page helpful?