Skip to content

Instantly share code, notes, and snippets.

@alexismp
Last active June 11, 2019 13:48
Show Gist options
  • Save alexismp/8baf8aba8c23fab26a9e8ae564a4508f to your computer and use it in GitHub Desktop.
Save alexismp/8baf8aba8c23fab26a9e8ae564a4508f to your computer and use it in GitHub Desktop.
csv2sheet, addEmptySheet
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