Google Sheets API 總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Sheets API 是符合 REST 樣式的介面,可讓您讀取及修改試算表資料。透過 Sheets API,您可以:
- 建立試算表
- 讀取及寫入試算表儲存格值
- 更新試算表格式
- 管理連結試算表
以下列出 Sheets API 中常用的字詞:
- 試算表
Google 試算表中的主要物件。其中可包含多個 Sheets
,每個 Sheets
都含有 Cells
中的結構化資訊。這個
spreadsheets
資源代表試算表。其中包含不重複的 spreadsheetId
值。
- 試算表 ID
- 試算表的專屬 ID。這是包含字母、數字和部分特殊字元的特定字串,可參照試算表,並可從試算表網址衍生而來。即使試算表名稱變更,試算表 ID 仍會保持不變。
https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit?gid=SHEET_ID#gid=SHEET_ID
- 試算表
試算表中的頁面或分頁。Sheets
資源代表試算表。其中包含不重複的數值 sheetId
值和工作表 title
,做為 SheetProperties
物件的一部分。
- 工作表 ID
- 試算表中特定工作表的專屬 ID。這是指包含參照工作表數字的特定整數,可從試算表的網址衍生而來。即使工作表名稱變更,工作表 ID 也不會改變。如需範例,請參閱「試算表 ID」。
- 儲存格
試算表中的個別文字或資料欄位。儲存格會排列成列和欄,並可分組為儲存格範圍。Cells
資源代表每個儲存格,但沒有專屬 ID 值。而是以資料列和資料欄座標識別儲存格。
- A1 標記
- 用來定義儲存格或儲存格範圍的語法,其中包含工作表名稱,以及使用欄字母和列號的起始和結束儲存格座標。在參照儲存格的絕對範圍時,這個方法最常見且實用。
Sheet1!A1:B2
是指 Sheet1 前兩列和前兩欄的所有儲存格。
Sheet1!A:A
則是指 Sheet1 第一欄中的所有儲存格。
Sheet1!1:2
是指 Sheet1 前兩列的所有儲存格。
Sheet1!A5:A
是指 Sheet1 第一欄的所有儲存格,從第 5 列開始。
A1:B2
是指第一個可見工作表的前兩列和前兩欄中的所有儲存格。
Sheet1
是指 Sheet1 中的所有儲存格。
'Jon's_Data'!A1:D5
是指名為「Jon's_Data」工作表的前五列和四欄中的所有儲存格。
'My Custom Sheet'!A:A
是指名為「My Custom Sheet」工作表第一欄中的所有儲存格。
'My Custom Sheet'
是指「我的自訂試算表」中的所有儲存格。
如果工作表名稱含有空格或特殊字元,請務必加上單引號。
提示:請盡可能為試算表中的物件使用不同的名稱。舉例來說,A1 (不含引號) 是指第一個顯示工作表中的儲存格 A1。'A1'
是指名為 A1 的工作表。同樣地,Sheet1 是指名為 Sheet1 的工作表。不過,如果有名為「Sheet1」的具名範圍,則 Sheet1 會參照該具名範圍,而 'Sheet1'
則會參照工作表。
- R1C1 標記法
- 用來定義儲存格或儲存格範圍的語法,其中包含工作表名稱,以及使用列號和欄號的起始和結束儲存格座標。這種方法不如 A1 標記法常見,但如果參照的儲存格範圍與特定儲存格的位置相關,這種方法就很有用。
Sheet1!R1C1:R2C2
參照 Sheet1 前兩列的前兩個儲存格。
R1C1:R2C2
是指第一個可見工作表頂端兩列的前兩個儲存格。
Sheet1!R[3]C[1]
是指目前儲存格下方三列、右方一欄的儲存格。
- 已命名範圍
- 已定義的儲存格或儲存格範圍,具有自訂名稱,可簡化應用程式中的參照。
FilterView
資源代表具名範圍。 - 受保護的範圍
- 定義的儲存格或儲存格範圍,無法修改。
ProtectedRange
資源代表受保護的範圍。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Google Sheets API Overview\n\nThe Google Sheets API is a RESTful interface that lets you read and modify a\nspreadsheet's data. The Sheets API lets you:\n\n- Create spreadsheets\n- Read and write spreadsheet cell values\n- Update spreadsheet formatting\n- Manage Connected Sheets\n\nThe following is a list of common terms used in the Sheets API:\n\n*Spreadsheet*\n\n: The primary object in Google Sheets. It can contain multiple `Sheets`, each\n with structured information contained in `Cells`. The\n [`spreadsheets`](/workspace/sheets/api/reference/rest/v4/spreadsheets)\n resource represents a spreadsheet. It contains a unique `spreadsheetId`\n value.\n\n *Spreadsheet ID*\n : The unique identifier for a spreadsheet. It's a particular string\n containing letters, numbers, and some special characters that reference a\n spreadsheet and it can be derived from the spreadsheet's URL. Spreadsheet\n IDs are stable, even if the spreadsheet name changes. \n\n https://docs.google.com/spreadsheets/d/\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e/edit?gid=\u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e#gid=\u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e\n\n*Sheet*\n\n: A page or tab within a spreadsheet. The\n [`Sheets`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets) resource\n represents a sheet. It contains a unique numeric `sheetId` value and sheet\n `title` as part of the\n [`SheetProperties`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#sheetproperties)\n object.\n\n *Sheet ID*\n : The unique identifier for a specific sheet within a spreadsheet. It's a\n particular integer containing numbers that reference a sheet and it can be\n derived from the spreadsheet's URL. Sheet IDs are stable, even if the sheet\n name changes. For an example, see [Spreadsheet ID](#spreadsheet-id).\n\n*Cell*\n\n: An individual field of text or data within a sheet. Cells are arranged in rows\n and columns, and can be grouped as a range of cells. The\n [`Cells`](/workspace/sheets/api/reference/rest/v4/spreadsheets/cells)\n resource represents each cell, but it doesn't have a unique ID value.\n Instead, row and column coordinates identify the cells.\n\n *A1 notation*\n : A syntax used to define a cell or range of cells with a string that\n contains the sheet name plus the starting and ending cell coordinates using\n column letters and row numbers. This method is the most common and useful\n when referencing an absolute range of cells.\n - `Sheet1!A1:B2` refers to all the cells in the first two rows and columns of Sheet1.\n - `Sheet1!A:A` refers to all the cells in the first column of Sheet1.\n - `Sheet1!1:2` refers to all the cells in the first two rows of Sheet1.\n - `Sheet1!A5:A` refers to all the cells of the first column of Sheet 1, from row 5 onward.\n - `A1:B2` refers to all the cells in the first two rows and columns of the first visible sheet.\n - `Sheet1` refers to all the cells in Sheet1.\n - `'Jon's_Data'!A1:D5` refers to all the cells in the first five rows and four columns of a sheet named \"Jon's_Data.\"\n - `'My Custom Sheet'!A:A` refers to all the cells in the first column of a sheet named \"My Custom Sheet.\"\n - `'My Custom Sheet'` refers to all the cells in \"My Custom Sheet\".\n\n Single quotes are required for sheet names with spaces or special characters.\n\n **Tip** : Where possible, use distinct names for objects in your spreadsheets. For example, A1 (without quotes) refers to cell A1 in the first visible sheet. `'A1'` refers to a sheet with the name A1. Similarly, Sheet1 refers to a sheet with the name Sheet1. However, if there's a named range titled \"Sheet1\", then Sheet1 refers to the named range and `'Sheet1'` refers to the sheet.\n\n *R1C1 notation*\n : A syntax used to define a cell or range of cells with a string that\n contains the sheet name plus the starting and ending cell coordinates using\n row numbers and column numbers. This method is less common than A1 notation,\n but can be useful when referencing a range of cells relative to a given\n cell's position.\n - `Sheet1!R1C1:R2C2` refers to the first two cells in the top two rows of Sheet1.\n - `R1C1:R2C2` refers to the first two cells in the top two rows of the first visible sheet.\n - `Sheet1!R[3]C[1]` refers to the cell that is three rows below and one column to the right of the current cell.\n\n *Named range*\n : A defined cell or range of cells with a custom name to simplify references\n throughout an application. A\n [`FilterView`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#filterview)\n resource represents a named range.\n\n *Protected range*\n : A defined cell or range of cells that cannot be modified. A\n [`ProtectedRange`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#protectedrange)\n resource represents a protected range.\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 learn how to configure and run a Sheets API app, try the\n [JavaScript quickstart](/workspace/sheets/api/quickstart/js)."]]