ONLYOFFICE 文档 9.0 开发者版:API 更新

2025年07月02日作者:Krystal

ONLYOFFICE 文档最新版已发布,包含多项更新,提供更丰富的功能、更灵活的自定义选项和更强的性能。开发者或集成者若想使用增强的 API,此版本值得深入探索。阅读本文了解详情。

ONLYOFFICE Docs 9.0 for developers: API updates

图表查看器

新增的图表查看器支持网页端、桌面端及移动网页端,无需第三方应用即可打开图表文件。

API 位置:diagram 文档类型已加入 documentType 参数。

ONLYOFFICE 文档 9.0 开发者指南:API 更新

支持新文件格式

ONLYOFFICE 持续扩展文件格式兼容性。9.0 版本支持查看 Markdown 和 OpenDocument 图形文件。

API 位置:新增对 odg 和 md 格式的打开支持。

配合图表查看器发布,新增 vsdm、vsdx、vssm、vssx、vstm、vstx 格式转换功能。查看 API

ONLYOFFICE 文档 9.0 开发者指南:API 更新

扩展自定义选项

9.0 版本大幅提升自定义能力,让最终用户按需定制使用体验。

新的界面主题

推出现代浅色和现代深色两个主题,优化编辑器视觉效果。

API 位置:editorConfig.customization.uiTheme 参数新增 theme-white 与 theme-night 主题 ID。

const config = {
  editorConfig: {
    customization: {
...
      uiTheme: "theme-white",
...

ONLYOFFICE 文档 9.0 开发者指南:API 更新

简体中文界面字号选择

新参数确保简体中文布局字号精准显示,支持西式或传统中文样式切换。

API 位置:editorConfig.customization.forceWesternFontSize 参数(默认值 false)。

const config = {
  editorConfig: {
    customization: {
....
 forceWesternFontSize: false,
...

隐藏用户头像

新参数可控制编辑器页眉用户头像显示,打造简洁无干扰界面。

API 位置:editorConfig.customization.layout.header.user 参数(默认值 true)。

const config = {
  editorConfig: {
    customization: {
...
layout: {
        header: {
          editMode: true,
          save: true,
          user: true,
          users: true,
        },

预加载性能优化

9.0 版本起,支持在打开文件前预加载静态资源(HTML/CSS/JS/字体)至浏览器缓存,加速文档编辑器首次加载。查看 API

提供两种方式:

1) 使用 ?preload=placeholder 参数

<div id="placeholder"></div>

<script type="text/javascript" src="https://documentserver/web-apps/apps/api/documents/api.js?preload=placeholder"></script>

2) 手动插入预加载 iframe

<iframe src="https://documentserver/web-apps/apps/api/documents/preload.html" style="display:none;"></iframe>

立即获取 ONLYOFFICE 文档开发者版最新版:

立即下载

插件与宏的 API 增强

内容控件自定义按钮通过 Asc.ButtonContentControl 类创建专属按钮,用 attachOnClick 定义操作并添加功能图标。查看 API

(function(window){
  window.Asc.plugin.init = function()
  {
    let button = new Asc.ButtonContentControl();
    button.icons = '/resources/check%scale%(default).png';
    button.attachOnClick(function(contentControlId){
      Asc.plugin.executeMethod("RemoveContentControl", [contentControlId]);
    });
 
    button = new Asc.ButtonContentControl();
    button.icons = '/resources/close%scale%(default).png';
    button.attachOnClick(function(contentControlId){
      Asc.plugin.executeMethod("RemoveContentControls", [[{"InternalId": contentControlId}]]);
    });
  }
})(window);

按索引定位幻灯片通过新增 GoToSlide 方法快速跳转至指定幻灯片。

expression.GoToSlide(slideNumber);

内容控件列表元素新增 ContentControlListElement 枚举简化文档内容控件管理。

异步计算在宏创建的自定义函数中管理异步请求。

(function () {
  /**
   * World Bank indicator value for a specific year.
   * @customfunction

   * @param   {string} country   ISO-3 code, e.g. "TUR"
   * @param   {string} indicator Indicator code, e.g. "SP.POP.TOTL"
   * @param   {number} year      Four-digit year, e.g. 2024
   * @returns {any}             Numeric value or #N/A
   *
   * @example =WB("TUR","SP.POP.TOTL",2024)
   */
  async function WB(country, indicator, year) {
    // Build URL (World Bank allows CORS)
    const url =
      `https://api.worldbank.org/v2/country/${country}/indicator/${indicator}` +
      `?format=json&per_page=20000`;

    try {
      const r = await fetch(url);
      const [meta, data] = await r.json();

      // Find the row for the requested year
      const row = data.find((v) => v.date === year.toString());
      if (!row || row.value == null) return "#N/A";

      return row.value;               // resolves the Promise
    } catch (e) {
      return "#ERROR";
    }
  }

  // Register the function so it becomes a sheet formula
  Api.AddCustomFunction(WB);
})();

新增示例

最新 API 文档新增更多开箱即用的 Document Builder 和宏示例,提升开发效率。

Builder 框架

新增各编辑器类型示例:

查看所有宏示例

Office API

Office JavaScript API 9.0 版新增大量方法,覆盖:

  • 内容控件
  • 自定义 XML
  • 表单
  • 自定义属性
  • 核心功能
  • 范围操作
  • 绘图
  • 演示文稿
  • 备注页

查看新增方法列表

创建免费的 ONLYOFFICE 账户

在线查看并协作编辑文本文档、电子表格、幻灯片、表单和 PDF 文件。