How can I create a Google Doc (or sheet or slide) file from a template through Google API

huangapple go评论47阅读模式
英文:

How can I create a Google Doc (or sheet or slide) file from a template through Google API

问题

代码部分不翻译,以下是翻译好的内容:

"The title says it all.
I want to use the GDrive API (or maybe the Google Doc, sheets or slide APIs) to create a document based on a template from the Template Gallery.

I already know how to create a Google Doc with GDrive API. But it's a blank one. I want to create a doc using one of my company templates (the same way you do when clicking on New -> Google Docs/Sheets/Slides -> From a Template menu in the GDrive web. See image)
How can I create a Google Doc (or sheet or slide) file from a template through Google API

The solution involving creating a blank document from a template, and using it as a source to copy it as a new doc doesn't work for me because it would be static. The templates are often modified and I don't want to have to periodically check if they have changed or not to update my reference docs.
1: https://i.stack.imgur.com/c3YpQ.png"

英文:

The title says it all.
I want to use the GDrive API (or maybe the Google Doc, sheets or slide APIs) to create a document based on a template from the Template Gallery.

I already know how to create a Google Doc with GDrive API. But it's a blank one. I want to create a doc using one of my company templates (the same way you do when clicking on New -> Google Docs/Sheets/Slides -> From a Template menu in the GDrive web. See image)
How can I create a Google Doc (or sheet or slide) file from a template through Google API

The solution involving creating a blank document from a template, and using it as a source to copy it as a new doc doesn't work for me because it would be static. The templates are often modified and I don't want to have to periodically check if they have changed or not to update my reference docs.

答案1

得分: 1

抱歉,代码部分不需要翻译。以下是翻译好的内容:

Templates with Drive API.

很不幸,看起来Drive、Sheets和Docs API不支持或没有任何方法可以访问默认模板或组织中的模板。

唯一的解决方法是将模板构建为普通的Drive文件,并获取特定文件的ID,以便运行:

files.copy

顺便说一下,在官方文档中也建议使用这种方法来合并文本到文档中,这可能是Docs API中关于模板的唯一提及:

它创建普通文档,就像您在帖子中建议的那样,然后将其编辑,然后稍后制作副本。

还有一件可能是一个绝佳主意的事情,那就是提出建议或发送反馈,请求允许从Drive API管理和创建模板的功能,您可以在这里进行操作:

References:

英文:

Templates with Drive API.

Unfortunately it seems that the Drive, Sheets and Docs API, do not support or have any methods that would allow access to either the default templates or the templates from the organization.

The only workaround would be to build a template as a normal Drive file and gather the ID of the particular file so you can run a:

> files.copy

Which by the way is also suggested over the official documentation on how to merge text into a document and probably the only mention of templates over the Docs API:

It creates normal documents as you suggest in your post and basically edit them to later just make a copy.

One more thing that could be an excellent idea would be to make a suggestion or send feedback to request a feature to allow the management and creation of templates from the Drive API, you can do so here:

References:

huangapple
  • 本文由 发表于 2023年2月24日 02:05:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定