次の方法で共有


Excel JavaScript API を使用してサポートを元に戻す

Excel アドインでは、元に戻す動作がサポートされています。 これにより、Excel JavaScript API によって実行されるアクションと、Excel でユーザーが実行したアクションの両方が保持されます。 これらのアクションは、個々のユーザーの 元に戻すスタック に保存され、ユーザーは必要に応じてアクションをステップバックできます。

グループ化を元に戻す

Excel JavaScript API では、元に戻すグループ化もサポートされています。 これにより、アドイン ユーザーに対して複数の API 呼び出しを 1 つの元に戻せるアクションにグループ化できます。 たとえば、アドインが 1 つのユーザー コマンドに応答して複数のワークシート間で複数の異なる更新を行う必要がある場合は、それらの更新をすべて 1 つのグループにラップできます。 これは、Excel.run 関数に提供される mergeUndoGroup プロパティを使用して行われます。

グループ内の API で元に戻すサポートが提供されていない場合は、操作をグループ化できないことを知らせる UndoNotSupported エラーがスローされます。 アドインはこのエラーを適切に処理し、ユーザーに適切なメッセージを表示する必要があります。

次のコード サンプルは、複数のアクションを true に設定mergeUndoGroupマージする方法を示しています。

重要

エラーを回避するために、グループ化されたすべての API 呼び出しで元に戻すことがサポートされていることを確認します。 詳細については、「 サポートされていない API」を 参照してください。

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

サポートされていない API

ほとんどの Excel JavaScript API では、元に戻す操作がサポートされています。 ただし、元に戻す動作をサポートしていない API の一覧については、次の表を参照してください。

ヒント

アドインでサポートされていない API を呼び出すと、その API 呼び出しからユーザーの元に戻すスタックがクリアされ、その時点を過ぎた操作を元に戻すことはできません。

API Excel on the webでサポートされます Excel on Windows および Excel on Mac でサポートされています 備考
AllowEditRange.address 不要 不要 なし
AllowEditRange.delete 不要 不要 なし
AllowEditRange.pauseProtection 不要 不要 なし
AllowEditRange.setPassword 不要 不要 なし
AllowEditRange.title 不要 不要 なし
AllowEditRangeCollection.add 不要 不要 なし
AllowEditRangeCollection.pauseProtection 不要 不要 なし
Chart.categoryLabelLevel 不要 不要 なし
Chart.seriesNameLevel 不要 不要 なし
ChartPivotOptions.showAxisFieldButtons 不要 はい なし
ChartPivotOptions.showLegendFieldButtons 不要 はい なし
ChartPivotOptions.showReportFilterFieldButtons 不要 はい なし
ChartPivotOptions.showValueFieldButtons 不要 はい なし
ChartTrendlineLabel.formula 不要 はい なし
DataConnectionCollection.refreshAll 不要 不要 なし
DocumentProperties.author​ 不要 はい なし
DocumentProperties.category 不要 はい なし
DocumentProperties.comments 不要 はい なし
DocumentProperties.company 不要 はい なし
DocumentProperties.keywords 不要 はい なし
DocumentProperties.manager 不要 はい なし
DocumentProperties.revisionNumber 不要 はい なし
DocumentProperties.subject 不要 はい なし
DocumentProperties.title 不要 はい なし
LinkedWorkbook.refresh 不要 不要 なし
LinkedWorkbookCollection.refreshAll 不要 いいえ なし
NamedItem.comment いいえ はい なし
PivotTableStyle.delete いいえ はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
PivotTableStyle.duplicate いいえ はい なし
PivotTableStyle.name いいえ はい なし
PivotTableStyleCollection.add いいえ はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
PivotTableStyleCollection.setDefault いいえ はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
Query.delete いいえ はい API では、Windows と Mac の Excel で元に戻すことがサポートされていますが、やり直しはサポートされていません。
Query.refresh いいえ はい API では、Windows と Mac では Excel の元に戻すことがサポートされていますが、やり直しはサポートされていません。
QueryCollection.refreshAll いいえ はい API では、Windows と Mac では Excel の元に戻すことがサポートされていますが、やり直しはサポートされていません。
Slicer.name いいえ はい なし
Slicer.nameInFormula いいえ はい なし
SlicerStyle.delete いいえ はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
SlicerStyle.duplicate いいえ はい なし
SlicerStyle.name いいえ はい なし
SlicerStyleCollection.add いいえ はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
SlicerStyleCollection.setDefault いいえ はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
Style.addIndent いいえ はい なし
Style.autoIndent いいえ はい なし
Style.formulaHidden いいえ はい なし
Style.horizontalAlignment いいえ はい なし
Style.includeAlignment いいえ はい なし
Style.includeBorder いいえ はい なし
Style.includeFont いいえ はい なし
Style.includeNumber いいえ はい なし
Style.includePatterns いいえ はい なし
Style.includeProtection いいえ はい なし
Style.indentLevel いいえ はい なし
Style.locked いいえ はい なし
Style.numberFormat いいえ はい なし
Style.numberFormatLocal いいえ はい なし
Style.orientation いいえ はい なし
Style.readingOrder いいえ はい なし
Style.shrinkToFit 不要 はい なし
Style.textOrientation 不要 はい なし
Style.verticalAlignment 不要 はい なし
Style.wrapText 不要 はい なし
TableStyle.delete 不要 はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
TableStyle.duplicate 不要 はい なし
TableStyle.name 不要 はい なし
TableStyleCollection.add 不要 はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
TableStyleCollection.setDefault 不要 はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
TimelineStyle.delete 不要 はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
TimelineStyle.duplicate 不要 はい なし
TimelineStyle.name 不要 はい なし
TimelineStyleCollection.add 不要 はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
TimelineStyleCollection.setDefault 不要 はい API では、 Windows と Mac の Excel での共同編集の元に戻すことはできません。
Workbook.close 不要 不要 なし
Workbook.insertWorksheetsFromBase64 不要 不要 なし
Workbook.save 不要 不要 なし
WorkbookProtection.protect 不要 不要 なし
WorkbookProtection.unprotect 不要 不要 なし
Worksheet.copy 不要 不要 なし
Worksheet.delete 不要 不要 なし
Worksheet.name はい 不要 なし
Worksheet.standardWidth 不要 はい なし
Worksheet.position はい 不要 なし
Worksheet.visibility​ はい 不要 なし
WorksheetCollection.addFromBase64 不要 不要 なし
WorksheetProtection.pauseProtection 不要 不要 なし
WorksheetProtection.protect 不要 不要 なし
WorksheetProtection.resumeProtection 不要 不要 なし
WorksheetProtection.setPassword 不要 不要 なし
WorksheetProtection.unprotect 不要 不要 なし
WorksheetProtection.updateOptions 不要 不要 なし

関連項目