[null,null,["最后更新时间 (UTC):2025-08-29。"],[],[],null,["# Use field masks\n\nField masks are a way for API callers to list the fields that a request should\nreturn or update. Using a\n[FieldMask](https://protobuf.dev/reference/protobuf/google.protobuf/#field-mask)\nallows the API to avoid unnecessary work and improves performance. A field mask\nis used for both the read and update methods in the Google Sheets API.\n\nRead with a field mask\n----------------------\n\nSpreadsheets can be large, and often you don't need every part of the\n[`Spreadsheet`](/workspace/sheets/api/reference/rest/v4/spreadsheets#resource:-spreadsheet)\nresource returned by a read request. You can limit what's returned in a\nSheets API response, using the `fields` URL parameter. For best\nperformance, [explicitly list only the fields you\nneed](/workspace/sheets/api/guides/performance#partial-response) in the reply.\n\nThe format of the fields parameter is the same as the [JSON encoding of a\nFieldMask](https://protobuf.dev/reference/protobuf/google.protobuf/#json-encoding-field-masks).\nStated briefly, multiple different fields are comma-separated and subfields are\ndot-separated. Field names can be specified in **camelCase** or\n**separated_by_underscores**. For convenience, multiple subfields from the same\ntype can be listed within parentheses.\n\nThe following\n[`spreadsheets.get`](/workspace/sheets/api/reference/rest/v4/spreadsheets/get)\nrequest example uses a field mask of\n`sheets.properties(sheetId,title,sheetType,gridProperties)` to fetch only the\nsheet ID, title,\n[`SheetType`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#SheetType),\nand\n[`GridProperties`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#GridProperties)\nof a\n[`SheetProperties`](/workspace/sheets/api/reference/rest/v4/spreadsheets/sheets#SheetProperties)\nobject on all sheets in a spreadsheet: \n\n```\nGET https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId?fields=sheets.properties(sheetId,title,sheetType,gridProperties)\n```\n\nThe response to this method call is a\n[`Spreadsheet`](/workspace/sheets/api/reference/rest/v4/spreadsheets#resource:-spreadsheet)\nobject containing the components requested in the field mask. Note that\n`sheetType=OBJECT` doesn't contain `gridProperties`: \n\n {\n \"sheets\": [\n {\n \"properties\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"title\": \"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\",\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 25\n }\n }\n },\n {\n \"properties\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"title\": \"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\",\n \"sheetType\": \"OBJECT\"\n }\n }\n ]\n }\n\nUpdate with a field mask\n------------------------\n\nSometimes you need to update only certain fields in an object while leaving the\nother fields unchanged. Update requests inside a\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\noperation use field masks to tell the API which fields are being changed. The\nupdate request ignores any fields that aren't specified in the field mask,\nleaving them with their current values.\n\nYou can also unset a field by not specifying it in the updated message, but\nadding the field to the mask. This clears whatever value the field previously\nhad.\n\nThe syntax for update field masks is the same as read field masks.\n| A field mask of `*` is treated like a wildcard and is shorthand for specifying every field in a message. The wildcard syntax can produce unwanted results if the API is updated in the future, as read-only fields and newly added fields may cause errors. For production applications, always list the specific fields being updated in field masks and avoid using `*` wildcards.\n\nThe following example uses the\n[`AddSheetRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#addsheetrequest)\nto add a new sheet of type `Grid`, freeze the first row, and color the new\nsheet's tab red: \n\n```\nPOST https://sheets.googleapis.com/v1/spreadsheets/spreadsheetId:batchUpdate\n``` \n\n {\n \"spreadsheetId\": \"\u003cvar translate=\"no\"\u003eSPREADSHEET_ID\u003c/var\u003e\",\n \"replies\": [\n {\n \"addSheet\": {\n \"properties\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"title\": \"\u003cvar translate=\"no\"\u003eTITLE\u003c/var\u003e\",\n \"index\": 6,\n \"sheetType\": \"GRID\",\n \"gridProperties\": {\n \"rowCount\": 1000,\n \"columnCount\": 26,\n \"frozenRowCount\": 1\n },\n \"tabColor\": {\n \"red\": 0.003921569\n },\n \"tabColorStyle\": {\n \"rgbColor\": {\n \"red\": 0.003921569\n }\n }\n }\n }\n }\n ]\n }"]]