【问题标题】:Unable to get the ID of opened .docx file in Docs Add-on无法在 Docs Add-on 中获取打开的 .docx 文件的 ID
【发布时间】:2021-11-29 09:19:09
【问题描述】:

我一直无法在 Google Docs Add-on 中获取 .docx 文件的 ID。 Id 存在于浏览器的 URL 中,但我找不到任何方法来获取浏览器 URL。

DocumentApp.getActiveDocument().getId() 方法没有帮助,因为它适用于 Google Docs 文件,而我在 Google doc 中打开的文件是 Microsoft Word 格式 (.docx) 文件。

我附上截图供参考:Reference image

有没有办法在 Google Docs Add-on 中获取 .docx 文件的 ID? 或者在谷歌文档插件中打开.docx时有什么方法可以获取浏览器的URL?

提前致谢。

【问题讨论】:

标签: google-apps-script google-docs docx


【解决方案1】:

答案:

对于非 Google Docs in Workspace 插件,无法检索此信息。

说明:

如您所述,DocumentApp 方法仅适用于 Google Docs 文件。

此外,仅当当前文档是 Google 文档时,才会填充 Workspace 插件的 Docs event object。我刚查了一下是这样的。

最后,在 Workspace 插件的上下文中无法检索此信息。

功能要求:

如果您认为此功能有用,可以考虑使用 this Issue Tracker template 提交功能请求。

【讨论】:

    【解决方案2】:

    使用此link 查看Workspace Addons 的事件对象。当你建立你的卡时,你就可以访问该事件。所以你应该可以在你的函数中使用docs.id 访问它。

    【讨论】:

    • { clientPlatform: 'web', docs: {}, commonEventObject: { platform: 'WEB', hostApp: 'DOCS' }, hostApp: 'docs' } 我在事件对象中得到了这个。我在docs.id or e.docs.id 中变得不确定。 @尼文
    猜你喜欢
    • 2022-01-04
    • 2021-06-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-21
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 2012-07-23
    相关资源
    最近更新 更多