Hi I am using googleapis npm package for work with spreadsheet. I have a function which use to copy spreadsheet but problem is that it only copy one sheet however my source spreadsheet has mupltiple sheets.
Here is my code:-
const { google } = require('googleapis');
var sheet_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
..
..
..
function copySpreadSheet(authClient, sheet_id) {
console.log('sheet_id', sheet_id)
const sheets = google.sheets({ version: 'v4', authClient });
sheets.spreadsheets.create({
auth: authClient,
resource: {
properties: {
title: "New Sheet " + new Date()
}
}
}, (err, response) => {
if (err) {
console.log('The API returned an error: ' + err);
return;
} else {
console.log(response.data)
var request = {
spreadsheetId: sheet_id,
sheetId: 0, // HERE I SOMETHING MISSING
resource: {
destinationSpreadsheetId: response.data.spreadsheetId
},
auth: authClient,
};
sheets.spreadsheets.sheets.copyTo(request, function (err, response2) {
if (err) {
console.error(err);
return;
}
console.log(response2.data);
});
console.log("Added");
}
});
}