Google 文档 API 概览
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Google Docs API,您可以在 Google 文档中创建和修改文档。
应用可以与 Docs API 集成,以根据用户提供的数据和系统提供的数据创建精美的文档。借助 Docs API,您可以:
- 将流程自动化
- 批量创建文档
- 设置文档格式
- 生成账单或合同
- 检索对象的特定属性
以下是 Docs API 中使用的常见术语列表:
- 文档 ID
相应文档的唯一标识符。它是一个包含字母、数字和一些特殊字符的特定字符串,用于引用文档,并且可以从文档的网址中派生出来。即使文档名称发生变化,文档 ID 也保持不变。如需详细了解如何查找此 ID,请参阅证件 ID。
https://docs.google.com/document/d/DOCUMENT_ID/edit
- 元素
构成文档的结构。文档的顶级元素包括 Body
、DocumentStyle
和 List
。
- Google Workspace 文档
Google Workspace 应用(例如 Google 文档)创建的文件。
Google 文档的 MIME 类型格式为 application/vnd.google-apps.document
。如需查看 MIME 类型列表,请参阅
Google Workspace 和 Google 云端硬盘支持的 MIME 类型。
- 索引
内容正文中的大多数元素都具有 startIndex
和 endIndex
属性。这些属性用于指示元素开头和结尾相对于其封装段开头的偏移量。
- 内嵌图片
显示在文档文本流中的图片。不是附件。
- 命名范围
一段连续的文本。NamedRange
是具有相同 namedRangeId
的一系列范围。命名范围允许开发者将文档的某些部分与任意用户定义的标签相关联,以便日后以编程方式读取或修改其内容。一个文档可以包含多个名称相同的命名范围,但每个命名范围都有一个唯一的 ID。
- Segment
包含结构或内容元素的 Body
、Header
、Footer
或 Footnote
。细分中的元素的索引相对于相应细分的开头。
- 建议
您可以在不更改原文的情况下对文档进行更改。如果所有者批准您的建议,那么修改建议便会替换原来的文本。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Google Docs API overview\n\nThe Google Docs API lets you create and modify documents in Google Docs.\n\nApplications can integrate with the Docs API to create polished\ndocuments from both user and system-provided data. The Docs API lets\nyou:\n\n- Automate processes\n- Create documentation in bulk\n- Format documents\n- Generate invoices or contracts\n- Retrieve specific attributes of objects\n\nThe following is a list of common terms used in the Docs API:\n\n*Document ID*\n\n: The unique identifier for a document. It's a particular string containing\n letters, numbers, and some special characters that reference a document and\n it can be derived from the document's URL. Document IDs are stable, even if\n the document name changes. For more information on how to find the ID, see\n [Document ID](/workspace/docs/api/concepts/document#document-id).\n\n https://docs.google.com/document/d/\u003cvar translate=\"no\"\u003eDOCUMENT_ID\u003c/var\u003e/edit\n\n*Element*\n\n: The structure that makes up a document. Top-level elements of a document\n include the [`Body`](/workspace/docs/api/reference/rest/v1/documents#body),\n [`DocumentStyle`](/workspace/docs/api/reference/rest/v1/documents#documentstyle), and\n [`List`](/workspace/docs/api/reference/rest/v1/documents#list).\n\n*Google Workspace document*\n\n: A file that a Google Workspace application, like Google Docs, creates.\n The MIME type format for Docs is\n `application/vnd.google-apps.document`. For a list of MIME types, see [Google Workspace and Google Drive supported MIME types](/drive/api/guides/mime-types).\n\n*Index*\n\n: Most *elements* within the content body have the `startIndex` and `endIndex`\n properties. These indicate the offset of an element's beginning and end,\n relative to the beginning of its enclosing *segment*.\n\n*Inline image*\n\n: An image that appears in the flow of text within a document. It's not an\n attachment.\n\n*Named range*\n\n: A contiguous range of text. A\n [`NamedRange`](/workspace/docs/api/reference/rest/v1/documents#namedrange) is a\n collection of ranges with the same `namedRangeId`. Named ranges allow\n developers to associate parts of a document with an arbitrary user-defined\n label so their contents can be programmatically read or edited later. A\n document can contain multiple named ranges with the same name, but every\n named range has a unique ID.\n\n*Segment*\n\n: The `Body`, [`Header`](/workspace/docs/api/reference/rest/v1/documents#header),\n [`Footer`](/workspace/docs/api/reference/rest/v1/documents#footer), or\n [`Footnote`](/workspace/docs/api/reference/rest/v1/documents#footnote) containing\n structural or content *elements* . The *indexes* of the elements within a\n segment are relative to the beginning of that segment.\n\n*Suggestion*\n\n: Changes to a document without changing the original text. If the owner\n approves your suggestions, they replace the original text.\n\nRelated topics\n--------------\n\n- To learn about developing with Google Workspace APIs, including handling\n authentication and authorization, refer to [Develop on\n Google Workspace](/workspace/guides/get-started).\n\n- To get a conceptual overview of a document, see\n [Document](/workspace/docs/api/concepts/document).\n\n- To learn how to configure and run a Docs API app, try the\n [JavaScript quickstart](/workspace/docs/api/quickstart/js)."]]