Another option (and one that is ultimately used) is to manually create a Google Sheet file with all the pre-configured formatting as a template. Then, instead of creating a new spreadsheet document in Google Drive, copy the template as follows:
var config = require('./config'); var google = require('googleapis'); function createSheetFromTemplate(user, templateFileId, done) { var oauth2Client = new google.auth.OAuth2(config.google.clientId, config.google.clientSecret); oauth2Client.setCredentials({ access_token: user.google.token, refresh_token: user.google.refreshToken, }); var drive = google.drive({ version: 'v2', auth: oauth2Client }); drive.files.copy({ fileId: templateFileId, resource: { title: 'New Google Sheet', parents: [{ id: 'root' }] } }, function(err, response) { if (err) done(err) initializeSpreadsheet(response.id, user, done); }); }
In this code, templateFileId is the file identifier of your shared template. You can get this file from your shared template file in any way, but the quick and dirty way is to simply copy and paste it from the URL when sharing it.
For example, if the sharing URL is:
https://docs.google.com/spreadsheets/d/1234567890abcdefghijklmnop/edit?usp=sharing
Then file ID is 1234567890abcdefghijklmnop
In my case, there is nothing private about the template itself, so I just shared it with “everyone with a link” configured to “view”, as described here:
https://support.google.com/drive/answer/2494886
If you need to keep the contents of the template file private, you need to find a way to make sure that the account specified in the config.google.clientId file has access to it.
Hope this helps!