简体   繁体   中英

using copyTo function in google sheets api in node.js

I am trying to use the copyTo function in google sheets api via node.js wherein it would copy a sheet from one spreadsheet to another. Here is my code:

function copySheet(auth){
var sheets = google.sheets('v4');
var spreadsheetID_foo = 'some spreadsheet id';
var spreadsheetID_test = 'another spreadsheet id';

sheets.spreadsheets.sheets.copyTo({
    auth: auth,
    sheetId: 0,
    spreadsheetId: spreadsheetID_test,
    resource: {properties: {destinationSpreadsheetId: spreadsheetID_foo}}
}, function(err,response){
    if(err) {
        console.log(err);
    }
    console.log('Data :', response);
});
}

However, an error pops and says "Missing required parameters: sheetId". But in the code, I already declared the said parameter. I have been successful in using other commands from the API but this copyTo function is one that I cant really figure out. Can someone out here guide me on what I did wrong? Thank you very much.

Check this documentation from Google Apps Script on how to use copyTo(spreadsheet) funtion.

It Copies the sheet to a given spreadsheet, which can be the same spreadsheet as the source. The copied sheet will be named "Copy of [original name]".

var source = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = source.getSheets()[0];

 var destination = SpreadsheetApp.openById('ID_GOES HERE');
 sheet.copyTo(destination);

// replace

resource: {properties: {destinationSpreadsheetId: spreadsheetID_foo}}

// with

resource: {destinationSpreadsheetId: spreadsheetID_foo}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM