适用于 Office 的 JavaScript APIJavaScript API for Office

借助适用于 Office 的 JavaScript API,您可以创建可与 Office 主机应用程序中的对象模型进行交互的 Web 应用程序。The JavaScript API for Office enables you to create web applications that interact with the object models in Office host applications. 你的应用程序将引用 office.js 库中,该库是一个脚本加载程序。Your application will reference the office.js library, which is a script loader. Office.js 库加载适用于正在运行外接程序的 Office 应用程序的对象模型。The office.js library loads the object models that are applicable to the Office application that is running the add-in. 你可以使用以下 JavaScript 对象模型:You can use the following JavaScript object models:

  • 公用 API - 与 Office 2013 一起引入的 API。Common APIs - APIs that were introduced with Office 2013. 这为所有 Office 主机应用程序加载 API,并将外接程序应用程序与 Office 客户端应用程序相连接。This is loaded for all Office host applications and connects your add-in application with the Office client application. 对象模型包含特定于 Office 客户端的 API 以及适用于多个 Office 客户端主机应用程序的 API。The object model contains APIs that are specific to Office clients, and APIs that are applicable to multiple Office client host applications. 所有这些内容位于通用 API 下。All of this content is under Common API. 此对象模型使用回调。This object model uses callbacks.

    Outlook 还使用通用 API 语法。Outlook also uses the Common API syntax. 代码中的别名 Office 下的全部内容包含可以用于编写与 Office 文档、工作簿、演示文稿、邮件项以及 Office 加载项中的项目中的内容交互的脚本的对象。如果加载项面向 Office 2013 及更高版本,则必须使用这些通用 API。Everything under the alias Office contains objects you can use to write scripts that interact with content in Office documents, worksheets, presentations, mail items, and projects from your Office Add-ins. You must use these Common APIs if your add-in will target Office 2013 and later. 此对象模型使用回调。This object model uses callbacks.

  • 特定于主机的 API - 与 Office 2016 一起引入的 API。Host-specific APIs - APIs that were introduced with Office 2016. 此对象模型提供特定于主机的强类型对象,这些对象对应于使用 Office 客户端时所看到的熟悉对象,并表示 Office JavaScript API 的未来。This object model provides host-specific strongly-typed objects that correspond to familiar objects that you see when you use Office clients, and represents the future of Office JavaScript APIs. 特定于主机的 JavaScript API 当前可用于 Excel、OneNote、PowerPoint 和 Word。Host-specific JavaScript APIs are currently available for Excel, OneNote, PowerPoint, and Word.

支持的主机应用程序Supported host applications

备注

Project 支持使用 JavaScript API 制作的加载项,但目前没有专为与 Project 交互而设计的 JavaScript API。Project supports add-ins made with the JavaScript API, but there's currently no JavaScript API designed specifically for interacting with Project. 你可以使用通用 API 来创建 Project 加载项。You can use the Common API to create Project add-ins.

了解有关支持的主机和其他要求的详细信息。Learn more about supported hosts and other requirements.

开放 API 规范Open API specifications

在我们设计和开发新的 API 以用于 Office 外接程序时,我们将使它们适用于开放 API 规范页的反馈。了解管道中的新增功能,并提供您对我们的设计规范的宝贵意见。As we design and develop new APIs for Office Add-ins, we'll make them available for your feedback on our Open API specifications page. Find out what new features are in the pipeline, and provide your input on our design specifications.

另请参阅See also