Last active
June 11, 2019 13:48
-
-
Save alexismp/8baf8aba8c23fab26a9e8ae564a4508f to your computer and use it in GitHub Desktop.
csv2sheet, addEmptySheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addEmptySheet(sheetsAPI, sheetName) { | |
return new Promise((resolve, reject) => { | |
const emptySheetParams = { | |
spreadsheetId: process.env.SPREADSHEET_ID, | |
resource: { | |
requests: [ | |
{ | |
addSheet: { | |
properties: { | |
title: sheetName, | |
index: 1, | |
gridProperties: { | |
rowCount: 2000, | |
columnCount: 26, | |
frozenRowCount: 1 | |
} | |
} | |
} | |
} | |
] | |
} | |
}; | |
sheetsAPI.spreadsheets.batchUpdate( emptySheetParams, function(err, response) { | |
if (err) { | |
reject("The Sheets API returned an error: " + err); | |
} else { | |
const sheetId = response.data.replies[0].addSheet.properties.sheetId; | |
console.log("Created empty sheet: " + sheetId); | |
resolve(sheetId); | |
} | |
} | |
); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment