如何使用谷歌驱动器API创build电子表格文件,并将默认标签标题设置为“Sheet1”以外的内容
我想通过谷歌驱动器(v3)API创build一个电子表格,其中:
- 我上传一个CSV数据来填充第一个标签
- 我可以将选项卡的名称设置为“Sheet1”以外的其他名称
我花了整晚爬行谷歌API的工作表(V4)和驱动器(V3),但仍然无法弄清楚这一个!
如果我不能这样做,似乎我将不得不发送一个额外的请求来更新工作表属性来改变标题后,我做了第一次上传。 如果可能,我想尽量避免,但我意识到这可能是唯一的方法。
以下是我要发送的API请求:
let fileMetadata = { name: name, title: 'rawData', //This does NOT get set! Tab appears as "Sheet1" mimeType: 'application/vnd.google-apps.spreadsheet' } let media = { mimeType: 'text/csv', body: data // The body data is the raw parsed CSV } var Google = google.drive('v3') Google.files.create({ auth: auth, media: media, resource: fileMetadata }, function(err, response) { if (err) { console.log('The API returned an error: ' + err) return done(err) } else { console.log('success!') console.log(response) } })
我尝试使用Sheet API创build一个新的电子表格,然后使用Method: spreadsheets.create
。 使用表单API之类的特定API可以为您提供更多专门的方法,例如添加图纸标题的属性(有关更多表单的特定方法)。
创build电子表格,返回新创build的电子表格。
// BEFORE RUNNING: // --------------- // 1. If not already done, enable the Google Sheets API // and check the quota for your project at // https://console.developers.google.com/apis/api/sheets // 2. Install the Node.js client library by running // `npm install googleapis --save` var google = require('googleapis'); var sheets = google.sheets('v4'); authorize(function(authClient) { var request = { resource: { // TODO: Add desired properties to the request body. }, auth: authClient }; sheets.spreadsheets.create(request, function(err, response) { if (err) { console.log(err); return; } // TODO: Change code below to process the `response` object: console.log(JSON.stringify(response, null, 2)); }); }); function authorize(callback) { // TODO: Change placeholder below to generate authentication credentials. See // https://developers.google.com/sheets/quickstart/nodejs#step_3_set_up_the_sample // // Authorize using one of the following scopes: // 'https://www.googleapis.com/auth/drive' // 'https://www.googleapis.com/auth/spreadsheets' var authClient = null; if (authClient == null) { console.log('authentication failed'); return; } callback(authClient); }
我使用了Try这个API
导致:
这也将在您的Google云端硬盘中。
希望这可以帮助。