Excel.RunOptions interface
- Extends
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/50-workbook/workbook-undo-grouping.yaml
// Use the `mergeUndoGroup` property of the `RunOptions` interface to group multiple operations into a single undo action.
await Excel.run({ mergeUndoGroup: true }, async (context) => {
const workbook = context.workbook;
const sheet = context.workbook.worksheets.getActiveWorksheet();
// Apply formatting to multiple ranges.
const headerRange = sheet.getRange("A1:D1");
headerRange.format.fill.color = "#4472C4";
headerRange.format.font.color = "white";
headerRange.format.font.bold = true;
await context.sync();
const dataRange = sheet.getRange("A2:D6");
dataRange.format.borders.getItem("EdgeTop").style = "Continuous";
dataRange.format.borders.getItem("EdgeBottom").style = "Continuous";
dataRange.format.borders.getItem("EdgeLeft").style = "Continuous";
dataRange.format.borders.getItem("EdgeRight").style = "Continuous";
await context.sync();
const totalRow = sheet.getRange("A6:D6");
totalRow.format.fill.color = "#D9E1F2";
totalRow.format.font.bold = true;
// Return focus to the workbook.
workbook.focus(); // This API is only supported on desktop. In Excel on the web, you must manually return focus to the worksheet after clicking the task pane button.
await context.sync();
console.log("Applied formatting with undo grouping. Use Ctrl+Z (Cmd+Z on Mac) once to undo all changes.");
});
Properties
| delay |
Determines whether Excel will delay the batch request until the user exits cell edit mode. When |
| merge |
Determines whether the batch requests should be merged to one undo group. When false, each |
Property Details
delayForCellEdit
Determines whether Excel will delay the batch request until the user exits cell edit mode.
When false, if the user is in cell edit when the batch request is processed by the host, the batch automatically fails. When true, the batch request is executed immediately if the user is not in cell edit mode, but if the user is in cell edit mode then the batch request is delayed until the user exits cell edit mode. The default behavior with no delayForCellEdit property specified is equivalent to when it is false.
delayForCellEdit?: boolean;
Property Value
boolean
mergeUndoGroup
Determines whether the batch requests should be merged to one undo group.
When false, each context.sync() call creates an undo record. When true, all context.sync() calls in a single Excel.run are merged into one undo group.
mergeUndoGroup?: boolean;
Property Value
boolean