ตัวอย่าง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ส่วนนี้จะแสดงcodelabที่คุณใช้เพื่อทำความคุ้นเคยกับ Google Sheets API ได้
นอกจากนี้ ยังมีชุดตัวอย่าง "สูตร" ที่แสดงวิธีแปลการดำเนินการใน Google ชีตที่ต้องการให้เป็นคำขอ API
โดยปกติแล้ว API จะมีวิธีมากกว่า 1 วิธีในการทำงานที่กำหนด เมื่อ
คุณตัดสินใจว่าจะเข้าถึงงานอย่างไร โปรดคำนึงถึงสิ่งต่อไปนี้
- หากต้องการอ่านหรือเขียนค่าเซลล์
spreadsheets.values
คอลเล็กชันจะเป็นตัวเลือกที่ดีกว่า
spreadsheets
คอลเล็กชัน ส่วนอินเทอร์เฟซของตัวแรกจะใช้งานง่ายกว่าสำหรับการดำเนินการอ่าน/เขียนแบบง่ายๆ
หากเป็นไปได้ ให้ใช้วิธีการแบบกลุ่ม
(spreadsheet.batchUpdate
,
spreadsheet.values.batchGet
,
และ
spreadsheet.values.batchUpdate
)
เพื่อรวมคำขอหลายรายการไว้ในการเรียกเมธอดเดียว การใช้วิธีการประมวลผลแบบเป็นชุดเหล่านี้จะช่วยเพิ่มประสิทธิภาพเนื่องจาก
- ลดค่าใช้จ่าย HTTP ของไคลเอ็นต์
- ลดจำนวนการค้นหาที่ดำเนินการ
- ลดจำนวนการแก้ไขในเอกสาร
- ตรวจสอบว่าการเปลี่ยนแปลงทั้งหมดในกลุ่มเป็นแบบอะตอม
สูตรอาหาร
ตัวอย่างที่แสดงในส่วนนี้จะสาธิตวิธีแสดงการดำเนินการทั่วไปใน
ชีตเป็นคำขอ Sheets API v4
ตัวอย่างเหล่านี้จะแสดงในรูปแบบคำขอ HTTP เพื่อให้เป็นกลางทางภาษา
ดูวิธีใช้โปรโตคอลคำขอ Sheets API ในภาษาหนึ่งๆ โดยใช้ไลบรารีของไคลเอ็นต์ Google API ได้ที่คำแนะนำอ่านและเขียนค่า
เซลล์และอัปเดต
สเปรดชีต
สูตรอาหารในส่วนนี้แบ่งออกเป็นหมวดหมู่ต่อไปนี้
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-29 UTC
[null,null,["อัปเดตล่าสุด 2025-08-29 UTC"],[],[],null,["# Samples\n\nThis section presents a\n[codelab](https://codelabs.developers.google.com/codelabs/sheets-api/) you can\nuse to become familiar with the Google Sheets API. Also provided are a set of\n\"recipe\" examples that demonstrate how to translate an intended Google Sheets\naction into an API request.\n\nOften there's more than one way to complete a given task with the API. When\nyou're deciding on how to approach a task, keep the following in mind:\n\n- If you need to read or write cell values, the [`spreadsheets.values`](/workspace/sheets/api/reference/rest/v4/spreadsheets.values) collection is a better choice than the [`spreadsheets`](/workspace/sheets/api/reference/rest/v4/spreadsheets) collection. The former's interface is easier to use for simple read/write operations.\n- Wherever possible, use the batch methods\n ([`spreadsheet.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets/batchUpdate),\n [`spreadsheet.values.batchGet`](/workspace/sheets/api/reference/rest/v4/spreadsheets.values/batchGet),\n and\n [`spreadsheet.values.batchUpdate`](/workspace/sheets/api/reference/rest/v4/spreadsheets.values/batchUpdate))\n to bundle multiple requests into a single method call. Using these batch\n methods improves efficiency as they:\n\n - Reduce client HTTP overhead.\n - Reduce the number of queries made.\n - Reduce the number of revisions on the doc.\n - Ensure atomicity of all the changes in the batch.\n\nRecipes\n-------\n\nThe examples listed in this section demonstrate how to express common actions in\nSheets as Sheets API v4 requests.\n\nThese examples are presented in the form of HTTP requests to be language\nneutral. To learn how to implement Sheets API request protocols in a\nspecific language using Google API client libraries, see the [Read \\& write cell\nvalues](/workspace/sheets/api/guides/values) and [Update\nspreadsheets](/workspace/sheets/api/guides/batchupdate) guides.\n\nRecipes in this section are divided into the following categories:\n\n- [Basic reading](/workspace/sheets/api/samples/reading)---Recipes that show how to read values from a sheet.\n- [Basic writing](/workspace/sheets/api/samples/writing)---Recipes that show how to write values to a sheet.\n- [Basic formatting](/workspace/sheets/api/samples/formatting)---Recipes that show how to change the appearance of sheets and cells.\n- [Charts](/workspace/sheets/api/samples/charts)---Recipes that show how to create and alter charts in a sheet.\n- [Conditional formatting](/workspace/sheets/api/samples/conditional-formatting)--- Recipes that show how to alter cell appearance based on conditions.\n- [Data operations](/workspace/sheets/api/samples/data)---Recipes that show how to create, move, and manipulate data in a spreadsheet.\n- [Named \\& protected\n ranges](/workspace/sheets/api/samples/ranges)---Recipes that show how to create, update, and remove named and protected ranges in a spreadsheet.\n- [Pivot tables](/workspace/sheets/api/samples/pivot-tables)---Recipes that show how to create pivot tables in a sheet.\n- [Row \\& column\n operations](/workspace/sheets/api/samples/rowcolumn)---Recipes that show how to add, remove, and move rows and columns, and update their properties.\n- [Sheet operations](/workspace/sheets/api/samples/sheet)---Recipes that show how to create, clear, copy, and delete sheets, and also control their properties."]]