Thursday, 13 April 2017

How to create a spreadsheet file with the google drive API, and set the default tab title to something other than "Sheet1"

I want to create a spreadsheet via the google drive(v3) API where:

  1. I upload a CSV of data to populate the first tab
  2. I am able to set the name of the tab to something other than "Sheet1"

I spent all night crawling the google API for sheets(v4) and drive(v3), but still can't figure this one out!

If I can't do it this way, it seems like I will have to send an additional request to update the sheet properties to change the title after I do the initial upload. I'd like to avoid that if possible, but I realize it might be the only way.

Here's the API request I'm sending:

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)

  }

})



via DirtyBirdNJ

No comments:

Post a Comment