Method: spreadsheets.values.append
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thêm các giá trị vào bảng tính. Phạm vi đầu vào được dùng để tìm kiếm dữ liệu hiện có và tìm "bảng" trong phạm vi đó. Các giá trị sẽ được thêm vào hàng tiếp theo của bảng, bắt đầu từ cột đầu tiên của bảng. Hãy xem hướng dẫn và mã mẫu để biết thông tin chi tiết cụ thể về cách phát hiện bảng và thêm dữ liệu.
Phương thức gọi phải chỉ định mã nhận dạng bảng tính, dải ô và valueInputOption
. valueInputOption
chỉ kiểm soát cách dữ liệu đầu vào được thêm vào trang tính (theo cột hoặc theo hàng), không ảnh hưởng đến ô mà dữ liệu bắt đầu được ghi vào.
Yêu cầu HTTP
POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{range}:append
URL sử dụng cú pháp Chuyển mã gRPC.
Tham số đường dẫn
Thông số |
spreadsheetId |
string
Mã của bảng tính cần cập nhật.
|
range |
string
Ký hiệu A1 của một dải ô để tìm bảng dữ liệu logic. Các giá trị được thêm vào sau hàng cuối cùng của bảng.
|
Tham số truy vấn
Thông số |
valueInputOption |
enum (ValueInputOption )
Cách diễn giải dữ liệu đầu vào.
|
insertDataOption |
enum (InsertDataOption )
Cách chèn dữ liệu đầu vào.
|
includeValuesInResponse |
boolean
Xác định xem phản hồi cập nhật có bao gồm các giá trị của các ô đã được thêm vào hay không. Theo mặc định, các phản hồi không bao gồm các giá trị đã cập nhật.
|
responseValueRenderOption |
enum (ValueRenderOption )
Xác định cách hiển thị các giá trị trong phản hồi. Tuỳ chọn kết xuất mặc định là FORMATTED_VALUE .
|
responseDateTimeRenderOption |
enum (DateTimeRenderOption )
Xác định cách hiển thị ngày, giờ và thời lượng trong phản hồi. Giá trị này sẽ bị bỏ qua nếu responseValueRenderOption là FORMATTED_VALUE . Tuỳ chọn hiển thị dateTime mặc định là SERIAL_NUMBER .
|
Nội dung yêu cầu
Nội dung yêu cầu chứa một bản sao của ValueRange
.
Nội dung phản hồi
Phản hồi khi cập nhật một dải giá trị trong bảng tính.
Nếu thành công, phần nội dung phản hồi sẽ chứa dữ liệu có cấu trúc sau:
Biểu diễn dưới dạng JSON |
{
"spreadsheetId": string,
"tableRange": string,
"updates": {
object (UpdateValuesResponse )
}
} |
Trường |
spreadsheetId |
string
Bảng tính mà bạn đã áp dụng nội dung cập nhật.
|
tableRange |
string
Dải ô (theo ký hiệu A1) của bảng mà các giá trị đang được thêm vào (trước khi các giá trị được thêm vào). Trống nếu không tìm thấy bảng nào.
|
updates |
object (UpdateValuesResponse )
Thông tin về các bản cập nhật đã được áp dụng.
|
Phạm vi uỷ quyền
Yêu cầu một trong các phạm vi OAuth sau:
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file
https://www.googleapis.com/auth/spreadsheets
Để biết thêm thông tin, hãy xem Hướng dẫn uỷ quyền.
InsertDataOption
Xác định cách dữ liệu hiện có thay đổi khi dữ liệu mới được nhập.
Enum |
OVERWRITE |
Dữ liệu mới sẽ ghi đè dữ liệu hiện có trong các khu vực mà dữ liệu mới được ghi. (Lưu ý: việc thêm dữ liệu vào cuối trang tính vẫn sẽ chèn các hàng hoặc cột mới để có thể ghi dữ liệu.) |
INSERT_ROWS |
Các hàng sẽ được chèn cho dữ liệu mới. |
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-03-22 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-03-22 UTC."],[],[],null,["# Method: spreadsheets.values.append\n\n- [HTTP request](#body.HTTP_TEMPLATE)\n- [Path parameters](#body.PATH_PARAMETERS)\n- [Query parameters](#body.QUERY_PARAMETERS)\n- [Request body](#body.request_body)\n- [Response body](#body.response_body)\n - [JSON representation](#body.AppendValuesResponse.SCHEMA_REPRESENTATION)\n- [Authorization scopes](#body.aspect)\n- [InsertDataOption](#InsertDataOption)\n- [Try it!](#try-it)\n\nAppends values to a spreadsheet. The input range is used to search for existing data and find a \"table\" within that range. Values will be appended to the next row of the table, starting with the first column of the table. See the [guide](https://developers.google.com/workspace/sheets/api/guides/values#appending_values) and [sample code](https://developers.google.com/workspace/sheets/api/samples/writing#append_values) for specific details of how tables are detected and data is appended.\n\nThe caller must specify the spreadsheet ID, range, and a [valueInputOption](/workspace/sheets/api/reference/rest/v4/ValueInputOption). The `valueInputOption` only controls how the input data will be added to the sheet (column-wise or row-wise), it does not influence what cell the data starts being written to.\n\n### HTTP request\n\n`POST https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{range}:append`\n\nThe URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.\n\n### Path parameters\n\n| Parameters ||\n|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `spreadsheetId` | `string` The ID of the spreadsheet to update. |\n| `range` | `string` The [A1 notation](https://developers.google.com/workspace/sheets/api/guides/concepts#cell) of a range to search for a logical table of data. Values are appended after the last row of the table. |\n\n### Query parameters\n\n| Parameters ||\n|--------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `valueInputOption` | `enum (`[ValueInputOption](/workspace/sheets/api/reference/rest/v4/ValueInputOption)`)` How the input data should be interpreted. |\n| `insertDataOption` | `enum (`[InsertDataOption](/workspace/sheets/api/reference/rest/v4/spreadsheets.values/append#InsertDataOption)`)` How the input data should be inserted. |\n| `includeValuesInResponse` | `boolean` Determines if the update response should include the values of the cells that were appended. By default, responses do not include the updated values. |\n| `responseValueRenderOption` | `enum (`[ValueRenderOption](/workspace/sheets/api/reference/rest/v4/ValueRenderOption)`)` Determines how values in the response should be rendered. The default render option is [FORMATTED_VALUE](/workspace/sheets/api/reference/rest/v4/ValueRenderOption). |\n| `responseDateTimeRenderOption` | `enum (`[DateTimeRenderOption](/workspace/sheets/api/reference/rest/v4/DateTimeRenderOption)`)` Determines how dates, times, and durations in the response should be rendered. This is ignored if [responseValueRenderOption](/workspace/sheets/api/reference/rest/v4/spreadsheets.values/append#body.QUERY_PARAMETERS.response_value_render_option) is [FORMATTED_VALUE](/workspace/sheets/api/reference/rest/v4/ValueRenderOption). The default dateTime render option is [SERIAL_NUMBER](/workspace/sheets/api/reference/rest/v4/DateTimeRenderOption). |\n\n### Request body\n\nThe request body contains an instance of [ValueRange](/workspace/sheets/api/reference/rest/v4/spreadsheets.values#ValueRange).\n\n### Response body\n\nThe response when updating a range of values in a spreadsheet.\n\nIf successful, the response body contains data with the following structure:\n\n| JSON representation |\n|-------------------------------------------------------------------------------------------------------------------------------------------------|\n| ``` { \"spreadsheetId\": string, \"tableRange\": string, \"updates\": { object (/workspace/sheets/api/reference/rest/v4/UpdateValuesResponse) } } ``` |\n\n| Fields ||\n|-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------|\n| `spreadsheetId` | `string` The spreadsheet the updates were applied to. |\n| `tableRange` | `string` The range (in A1 notation) of the table that values are being appended to (before the values were appended). Empty if no table was found. |\n| `updates` | `object (`[UpdateValuesResponse](/workspace/sheets/api/reference/rest/v4/UpdateValuesResponse)`)` Information about the updates that were applied. |\n\n### Authorization scopes\n\nRequires one of the following OAuth scopes:\n\n- `https://www.googleapis.com/auth/drive`\n- `https://www.googleapis.com/auth/drive.file`\n- `https://www.googleapis.com/auth/spreadsheets`\n\nFor more information, see the [Authorization guide](/workspace/guides/configure-oauth-consent).\n\nInsertDataOption\n----------------\n\nDetermines how existing data is changed when new data is input.\n\n| Enums ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `OVERWRITE` | The new data overwrites existing data in the areas it is written. (Note: adding data to the end of the sheet will still insert new rows or columns so the data can be written.) |\n| `INSERT_ROWS` | Rows are inserted for the new data. |"]]