[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-29 (世界標準時間)。"],[],[],null,["# Sheet operations\n\nThe Google Sheets API lets you create, clear, copy, and delete sheets, and also\ncontrol their properties. The examples on this page illustrate how you can\nachieve some common Sheets operations with the\nSheets API.\n\nThese examples are presented in the form of HTTP requests to be language\nneutral. To learn how to implement a batch update in different languages using\nthe Google API client libraries, see [Update\nspreadsheets](/workspace/sheets/api/guides/batchupdate#example).\n\nIn these examples, the placeholders \u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e and \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e\nindicates where you would provide those IDs. You can find the [spreadsheet\nID](/workspace/sheets/api/guides/concepts#spreadsheet) in the spreadsheet URL. You can get\nthe [sheet ID](/workspace/sheets/api/guides/concepts#sheet) by using the\n[`spreadsheets.get`](/workspace/sheets/api/reference/rest/v4/spreadsheets/get) method. The\nranges are specified using [A1 notation](/workspace/sheets/api/guides/concepts#cell). An\nexample range is Sheet1!A1:D5.\n\nAdd a sheet\n-----------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`AddSheetRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#addsheetrequest)\nto add a sheet to a spreadsheet, while also setting the title, grid size, and\ntab color.\n\nThe response consists of a\n[`AddSheetResponse`](/workspace/sheets/api/reference/rest/v4/spreadsheets/response#addsheetresponse),\nwhich contains an object with the created sheet's properties (such as its\n\u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e).\n\nThe request protocol is shown below. \n\n POST https://sheets.googleapis.com/v4/spreadsheets/\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e:batchUpdate\n\n```text\n{\n \"requests\": [\n {\n \"addSheet\": {\n \"properties\": {\n \"title\": \"Deposits\",\n \"gridProperties\": {\n \"rowCount\": 20,\n \"columnCount\": 12\n },\n \"tabColor\": {\n \"red\": 1.0,\n \"green\": 0.3,\n \"blue\": 0.4\n }\n }\n }\n }\n ]\n}\n```\n\nClear a sheet of all values while preserving formats\n----------------------------------------------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`UpdateCellsRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#updatecellsrequest)\nto remove all values from a sheet while leaving the formatting unaltered.\n\nSpecifying the\n[`userEnteredValue`](/workspace/sheets/api/reference/rest/v4/spreadsheets/cells) field\nwithout a corresponding value is interpreted as an instruction to clear values\nin the range. This setting can be used with other fields as well. For example,\nchanging the `fields` value to\n[`userEnteredFormat`](/workspace/sheets/api/reference/rest/v4/spreadsheets/cells) removes\nall formatting supported by the Sheets API\nfrom the sheet, but leaves the cell values unaltered.\n\nThe request protocol is shown below. \n\n POST https://sheets.googleapis.com/v4/spreadsheets/\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e:batchUpdate\n\n {\n \"requests\": [\n {\n \"updateCells\": {\n \"range\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e\n },\n \"fields\": \"userEnteredValue\"\n }\n }\n ]\n }\n\nCopy a sheet from one spreadsheet to another\n--------------------------------------------\n\nThe following\n[`spreadsheet.sheets.copyTo`](/workspace/sheets/api/reference/rest/v4/spreadsheets.sheets/copyTo)\ncode sample shows how to copy a single sheet specified by \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e\nfrom one spreadsheet to another spreadsheet.\n\nThe \u003cvar translate=\"no\"\u003eTARGET_SPREADSHEET_ID\u003c/var\u003e variable in the request body specifies the\ndestination spreadsheet. The copy retains all values, formatting, formulas, and\nother properties of the original. The title of the copied sheet is set to \"Copy\nof \\[original sheet title\\]\".\n\nThe response consists of a\n[`SheetProperties`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#SheetProperties)\nobject describing the properties of the created sheet.\n\n\u003cbr /\u003e\n\n POST https://sheets.googleapis.com/v4/spreadsheets/\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e/sheets/\u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e:copyTo\n\n {\n \"destinationSpreadsheetId\": \"\u003cvar translate=\"no\"\u003eTARGET_SPREADSHEET_ID\u003c/var\u003e\"\n }\n\nDelete a sheet\n--------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`DeleteSheetRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#deletesheetrequest)\nto delete a sheet specified by \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e.\n\nThe request protocol is shown below. \n\n POST https://sheets.googleapis.com/v4/spreadsheets/\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e:batchUpdate\n\n {\n \"requests\": [\n {\n \"deleteSheet\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e\n }\n }\n ]\n }\n\nRead sheet data\n---------------\n\nThe following\n[`spreadsheets.get`](/workspace/sheets/api/reference/rest/v4/spreadsheets/get) code sample\nshows how to get [sheet](/workspace/sheets/api/guides/concepts#sheet) property information\nfrom a [spreadsheet](/workspace/sheets/api/guides/concepts#spreadsheet), specified by \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e\nand \u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e. This method is often used to determine the\nmetadata of sheets within a specific spreadsheet, so additional operations can\ntarget those sheets. The `fields` query parameter specifies only sheet property\ndata should be returned (as opposed to cell value data or data related to the\nentire spreadsheet).\n\n\u003cbr /\u003e\n\n GET https://sheets.googleapis.com/v4/spreadsheets/\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e?&fields=sheets.properties\n\nThe response consists of a\n[`Spreadsheet`](/workspace/sheets/api/reference/rest/v4/spreadsheets#resource-spreadsheet)\nresource, which contains a\n[`Sheet`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#Sheet) object with\n[`SheetProperties`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#SheetProperties)\nelements. If a given response field is set to the default value, it's omitted\nfrom the response. \n\n {\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"title\": \"Sheet1\",\n \"index\": 0,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 100,\n \"columnCount\": 20,\n \"frozenRowCount\": 1\n }\n \"tabColor\": {\n \"blue\": 1.0\n }\n },\n ...\n ],\n }"]]