[英]How to add new google spreadsheet and update using javascript
Im able to get the spreadsheet data from the below reference https://developers.google.com/sheets/quickstart/js#step_3_run_the_sample 我无法从以下参考中获取电子表格数据https://developers.google.com/sheets/quickstart/js#step_3_run_the_sample
but I didn't found any sample for creating or updating spreadsheet from javascript. 但我没有找到用于从javascript创建或更新电子表格的任何示例。
How can I create a new spreadsheet and update it using javascript v4 google API. 如何创建新的电子表格并使用javascript v4 google API更新它。
Create a spreadsheet using Spreadsheet API: 使用Spreadsheet API 创建电子表格:
Make an HTTP requests like: 发出HTTP请求,例如:
POST https://sheets.googleapis.com/v4/spreadsheets
POST
https://sheets.googleapis.com/v4/spreadsheets
This POST request comes with a request body. 该POST请求带有请求正文。 The request body looks something like:
请求正文看起来像:
{
"spreadsheetId": string,
"properties": {
object(SpreadsheetProperties)
},
"sheets": [
{
object(Sheet)
}
],
"namedRanges": [
{
object(NamedRange)
}
],
}
Don't forget to enable the following scopes: 不要忘记启用以下范围:
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/spreadsheets
Try it in the oauth playground . 在oauth游乐场尝试一下。
Updating Spreadsheets: 更新电子表格:
You'll be making use of batchUpdate. 您将使用batchUpdate。 This method lets you update any of the spreadsheet details.
此方法使您可以更新任何电子表格详细信息。 Changes are grouped together in a batch so that if one request fails, none of the other (potentially dependent) changes is written.
更改被成批地分组在一起,因此,如果一个请求失败,则不会写入其他任何更改(可能是相关的)。 The batchUpdate method works by taking one or more Request objects, each one specifying a single kind of request to perform.
batchUpdate方法通过采用一个或多个Request对象来工作,每个对象都指定一种要执行的请求。 There are many different kinds of requests.
有许多不同种类的请求。 Here's a breakdown on the types of requests, grouped into different categories.
以下是对请求类型的细分,分为不同的类别。
More of that in Updating Spreadsheets docs . 有关更新电子表格文档的更多信息 。 Format looks like:
格式如下:
POST .../v4/spreadsheets/spreadsheetId:batchUpdate
Request body: 要求正文:
{
"requests": [{
"updateSpreadsheetProperties": {
"properties": {"title": "My New Title"},
"fields": "title"
}
}]
}
Full sample here . 完整样本在这里 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.