You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Excel JavaScript API保存文档?是否有类Word Document API的接口?

Using Excel JavaScript API to Save Excel Documents

Absolutely! You can save Excel documents using the Excel JavaScript API, and there’s a direct equivalent to Word’s Document API for this exact task. Let’s break it down clearly:

Core Save Functionality (Mirroring Word’s Document API)

In Excel’s JS API, the Workbook object acts as the equivalent of Word’s Document object—it’s the top-level container for all file-related operations. It offers two key methods for saving:

1. Save changes to the existing workbook

This works just like clicking the "Save" button in Excel, writing any pending changes back to the original file:

await Excel.run(async (context) => {
  const workbook = context.workbook;
  workbook.save();
  await context.sync();
  console.log("Workbook saved successfully!");
});

2. Save as a new file (Save As)

If you need to create a copy with a new name or location, use the saveAs() method—just pass the desired file name as a parameter:

await Excel.run(async (context) => {
  const workbook = context.workbook;
  // Replace with your target file name
  workbook.saveAs("MyNewExcelFile.xlsx");
  await context.sync();
  console.log("Workbook saved as a new file!");
});

Important Notes

  • Cross-environment support: These methods work seamlessly across Excel for the web, Excel desktop (Windows/macOS), and Excel for iOS when used in an Office Add-in.
  • Permissions: Ensure your add-in has the WriteDocument permission declared in its manifest—this is required to perform save operations.
  • Auto-save behavior: If the workbook has auto-save enabled (common for cloud-stored files like OneDrive/SharePoint), save() will trigger an immediate cloud sync instead of prompting the user.

内容的提问来源于stack exchange,提问作者RichaS

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:33:44