Google Sheets API를 사용하면 다양한 방식으로 스프레드시트 내의 데이터를 조작할 수 있습니다. Sheets UI를 사용하는 사용자에게 제공되는 대부분의 기능은 Sheets API로도 사용할 수 있습니다. 이 페이지의 예에서는 Sheets API를 사용하여 일반적인 스프레드시트 작업을 수행하는 방법을 보여줍니다.
이러한 예는 언어에 구애받지 않도록 HTTP 요청의 형태로 제공됩니다. Google API 클라이언트 라이브러리를 사용하여 여러 언어로 일괄 업데이트를 구현하는 방법을 알아보려면 스프레드시트 업데이트를 참고하세요.
이 예에서 자리표시자 SPREADSHEET_ID 및 SHEET_ID는 이러한 ID를 제공할 위치를 나타냅니다. 스프레드시트 URL에서 스프레드시트 ID를 확인할 수 있습니다. spreadsheets.get 메서드를 사용하여 시트 ID를 가져올 수 있습니다. 범위는 A1 표기법을 사용하여 지정됩니다. 예를 들어 범위는 Sheet1!A1:D5입니다.
POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID:batchUpdate
{"requests":[{"setDataValidation":{"range":{"sheetId":SHEET_ID,"startRowIndex":0,"endRowIndex":10,"startColumnIndex":0,"endColumnIndex":4},"rule":{"condition":{"type":"NUMBER_GREATER","values":[{"userEnteredValue":"5"}]},"inputMessage":"Value must be > 5","strict":true}}}]}
셀 서식 복사 및 붙여넣기
다음 spreadsheets.batchUpdate 코드 샘플은 CopyPasteRequest를 사용하여 A1:D10 범위의 서식만 복사하고 동일한 시트의 F1:I10 범위에 붙여넣는 방법을 보여줍니다. 이 메서드는 PASTE_FORMAT와 함께 PasteType enum을 사용하여 서식과 데이터 유효성 검사만 붙여넣습니다. A1:D10의 원래 값은 변경되지 않습니다.
요청 프로토콜은 다음과 같습니다.
POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID:batchUpdate
다음 spreadsheets.batchUpdate 코드 샘플은 =FLOOR(A1*PI()) 수식을 B1:D10 범위에 복사하기 위해 RepeatCellRequest를 사용하는 방법을 보여줍니다. 수식의 범위는 왼쪽 상단 셀부터 시작하여 범위의 각 행과 열에 대해 자동으로 증가합니다. 예를 들어 셀 B1에는 =FLOOR(A1*PI()) 수식이 있고 셀 D6에는 =FLOOR(C6*PI()) 수식이 있습니다.
요청 프로토콜은 다음과 같습니다.
POST https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEET_ID:batchUpdate
[[["이해하기 쉬움","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(UTC)"],[],[],null,["# Data operations\n\nThe Google Sheets API lets you manipulate data within spreadsheets in various\nways. Most functionality that's available to users working with the\nSheets UI is also possible to do with the\nSheets API. The examples on this page illustrate how you can achieve\nsome common spreadsheet operations with the Sheets 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\nApply data validation to a range\n--------------------------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`SetDataValidationRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#setdatavalidationrequest)\nto apply a data validation rule, where \"value \\\u003e 5\", to every cell in the range A1:D10.\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 \"/workspace/sheets/api/reference/rest/v4/spreadsheets/request#setdatavalidationrequest\": {\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#gridrange\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eSHEET_ID\u003c/span\u003e\u003c/var\u003e,\n \"startRowIndex\": 0,\n \"endRowIndex\": 10,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 4\n },\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#datavalidationrule\": {\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#booleancondition\": {\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#conditiontype\": \"NUMBER_GREATER\",\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#conditionvalue\": [\n {\n \"userEnteredValue\": \"5\"\n }\n ]\n },\n \"inputMessage\": \"Value must be \u003e 5\",\n \"strict\": true\n }\n }\n }\n ]\n }\n\nCopy \\& paste cell formatting\n-----------------------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`CopyPasteRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#copypasterequest)\nto copy the formatting only in the range A1:D10 and paste it to the F1:I10 range\nin the same sheet. The method uses the\n[`PasteType`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#pastetype) enum\nwith `PASTE_FORMAT` to paste the formatting and data validation only. The\noriginal values in A1:D10 remain unchanged.\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 \"copyPaste\": {\n \"source\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"startRowIndex\": 0,\n \"endRowIndex\": 10,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 4\n },\n \"destination\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"startRowIndex\": 0,\n \"endRowIndex\": 10,\n \"startColumnIndex\": 5,\n \"endColumnIndex\": 9\n },\n \"pasteType\": \"PASTE_FORMAT\",\n \"pasteOrientation\": \"NORMAL\"\n }\n }\n ]\n }\n\nCut \\& paste cells\n------------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`CutPasteRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#cutpasterequest).\nIt cuts the range A1:D10 and uses the\n[`PasteType`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#pastetype) enum\nwith `PASTE_NORMAL` to paste its values, formulas, formatting, and merges to the\nF1:I10 range in the same sheet. The original source range cell contents are\nremoved.\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 \"cutPaste\": {\n \"source\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"startRowIndex\": 0,\n \"endRowIndex\": 10,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 4\n },\n \"destination\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"rowIndex\": 0,\n \"columnIndex\": 5\n },\n \"pasteType\": \"PASTE_NORMAL\"\n }\n }\n ]\n }\n\nRepeat a formula over a range\n-----------------------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`RepeatCellRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#repeatcellrequest)\nto copy the formula `=FLOOR(A1*PI())` to the range B1:D10. The formula's range\nautomatically increments for each row and column in the range, starting with the\nupper left cell. For example, cell B1 has the formula `=FLOOR(A1*PI())`, while\ncell D6 has the formula `=FLOOR(C6*PI())`.\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 \"repeatCell\": {\n \"range\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003eSHEET_ID\u003c/var\u003e,\n \"startRowIndex\": 0,\n \"endRowIndex\": 10,\n \"startColumnIndex\": 1,\n \"endColumnIndex\": 4\n },\n \"cell\": {\n \"userEnteredValue\": {\n \"formulaValue\": \"=FLOOR(A1*PI())\"\n }\n },\n \"fields\": \"userEnteredValue\"\n }\n }\n ]\n }\n\nSort a range with multiple sorting specifications\n-------------------------------------------------\n\nThe following\n[`spreadsheets.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate)\ncode sample shows how to use the\n[`SortRangeRequest`](/workspace/sheets/api/reference/rest/v4/spreadsheets/request#sortrangerequest)\nto sort the range A1:D10, first by column B in ascending order, then by column C\nin descending order, then by column D in descending order.\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 \"/workspace/sheets/api/reference/rest/v4/spreadsheets/request#sortrangerequest\": {\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#gridrange\": {\n \"sheetId\": \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eSHEET_ID\u003c/span\u003e\u003c/var\u003e,\n \"startRowIndex\": 0,\n \"endRowIndex\": 10,\n \"startColumnIndex\": 0,\n \"endColumnIndex\": 4\n },\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#sortspec\": [\n {\n \"dimensionIndex\": 1,\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#sortorder\": \"ASCENDING\"\n },\n {\n \"dimensionIndex\": 2,\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#sortorder\": \"DESCENDING\"\n },\n {\n \"dimensionIndex\": 3,\n \"/workspace/sheets/api/reference/rest/v4/spreadsheets#sortorder\": \"DESCENDING\"\n }\n ]\n }\n }\n ]\n }"]]