Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit focus mode

Undo support with the Excel JavaScript API (preview)

  • 2025-06-04
Feedback

In this article

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.

Undo grouping

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(); });

Unsupported APIs

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.

APISupported in Excel on the webSupported in Excel on Windows and Excel on MacNotes
AllowEditRange.addressNoNoNone
AllowEditRange.deleteNoNoNone
AllowEditRange.pauseProtectionNoNoNone
AllowEditRange.setPasswordNoNoNone
AllowEditRange.titleNoNoNone
AllowEditRangeCollection.addNoNoNone
AllowEditRangeCollection.pauseProtectionNoNoNone
Chart.categoryLabelLevelNoNoNone
Chart.seriesNameLevelNoNoNone
ChartPivotOptions.showAxisFieldButtonsNoYesNone
ChartPivotOptions.showLegendFieldButtonsNoYesNone
ChartPivotOptions.showReportFilterFieldButtonsNoYesNone
ChartPivotOptions.showValueFieldButtonsNoYesNone
ChartTrendlineLabel.formulaNoYesNone
DataConnectionCollection.refreshAllNoNoNone
DocumentProperties.author​NoYesNone
DocumentProperties.categoryNoYesNone
DocumentProperties.commentsNoYesNone
DocumentProperties.companyNoYesNone
DocumentProperties.keywordsNoYesNone
DocumentProperties.managerNoYesNone
DocumentProperties.revisionNumberNoYesNone
DocumentProperties.subjectNoYesNone
DocumentProperties.titleNoYesNone
LinkedWorkbook.refreshNoNoNone
LinkedWorkbookCollection.refreshAllNoNoNone
NamedItem.commentNoYesNone
PivotTableStyle.deleteNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
PivotTableStyle.duplicateNoYesNone
PivotTableStyle.nameNoYesNone
PivotTableStyleCollection.addNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
PivotTableStyleCollection.setDefaultNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
Query.deleteNoYesAPI supports undo in Excel on Windows and Mac but doesn't support redo.
Query.refreshNoYesAPI supports undo Excel on Windows and Mac but doesn't support redo.
QueryCollection.refreshAllNoYesAPI supports undo Excel on Windows and Mac but doesn't support redo.
Slicer.nameNoYesNone
Slicer.nameInFormulaNoYesNone
SlicerStyle.deleteNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
SlicerStyle.duplicateNoYesNone
SlicerStyle.nameNoYesNone
SlicerStyleCollection.addNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
SlicerStyleCollection.setDefaultNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
Style.addIndentNoYesNone
Style.autoIndentNoYesNone
Style.formulaHiddenNoYesNone
Style.horizontalAlignmentNoYesNone
Style.includeAlignmentNoYesNone
Style.includeBorderNoYesNone
Style.includeFontNoYesNone
Style.includeNumberNoYesNone
Style.includePatternsNoYesNone
Style.includeProtectionNoYesNone
Style.indentLevelNoYesNone
Style.lockedNoYesNone
Style.numberFormatNoYesNone
Style.numberFormatLocalNoYesNone
Style.orientationNoYesNone
Style.readingOrderNoYesNone
Style.shrinkToFitNoYesNone
Style.textOrientationNoYesNone
Style.verticalAlignmentNoYesNone
Style.wrapTextNoYesNone
TableStyle.deleteNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
TableStyle.duplicateNoYesNone
TableStyle.nameNoYesNone
TableStyleCollection.addNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
TableStyleCollection.setDefaultNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
TimelineStyle.deleteNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
TimelineStyle.duplicateNoYesNone
TimelineStyle.nameNoYesNone
TimelineStyleCollection.addNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
TimelineStyleCollection.setDefaultNoYesAPI doesnot support co-authoring undo in Excel on Windows and Mac.
Workbook.closeNoNoNone
Workbook.insertWorksheetsFromBase64NoNoNone
Workbook.saveNoNoNone
WorkbookProtection.protectNoNoNone
WorkbookProtection.unprotectNoNoNone
Worksheet.copyNoNoNone
Worksheet.deleteNoNoNone
Worksheet.nameYesNoNone
Worksheet.standardWidthNoYesNone
Worksheet.positionYesNoNone
Worksheet.visibility​YesNoNone
WorksheetCollection.addFromBase64NoNoNone
WorksheetProtection.pauseProtectionNoNoNone
WorksheetProtection.protectNoNoNone
WorksheetProtection.resumeProtectionNoNoNone
WorksheetProtection.setPasswordNoNoNone
WorksheetProtection.unprotectNoNoNone
WorksheetProtection.updateOptionsNoNoNone

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNo

In this article

Was this page helpful?

YesNo