简体   繁体   English

如何使用javascript添加新的Google电子表格和更新

[英]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.

相关问题 如何使用Google表格API + Javascript更新电子表格 - How to update spreadsheet using Google Sheets API + Javascript 使用JavaScript以编程方式更新Google电子表格? - Programmatically update Google Spreadsheet with JavaScript? 使用 javascript 在 Google 电子表格中添加行 - Add row in google Spreadsheet with javascript 更新/添加数据到Google Spreadsheet数据库 - Update/Add data to Google Spreadsheet Database 如何在 Node.js 中使用 googleapis 创建新的 Google 电子表格 - How to Create New Google Spreadsheet Using googleapis in Node.js Google电子表格更新的正确语法-Javascript - Correct syntax for Google Spreadsheet update - Javascript 如何使用 JavaScript 将数据从 HTML 表单发送到 Google 电子表格? - How to send data from HTML form to Google Spreadsheet using JavaScript? 如何使用 JavaScript/jQuery 更改 Google 电子表格中的活动表? - How to change active sheet in Google Spreadsheet using JavaScript/jQuery? 使用Google电子表格更新Fusion Table - Using Google Spreadsheet to Update Fusion Table 在Google脚本中使用JavaScript将信息传输到电子表格,但电子表格显示未定义 - Using JavaScript in Google Scripts to transfer information to spreadsheet, but spreadsheet shows undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM