Monday, 22 May 2017

How to access active worksheet using nodejs and GAS?

I am trying to get active worksheet from google spreadsheet , but i am not able to get current active worksheet. I have tried a lot.

Here is my calling script from nodejs :

        function callAppsScript() {
              var scriptId ='myscriptid' 
                                    var script = google.script('v1');
                                        var auth = getOAuthClient();
                                        auth.setCredentials({                                   
                                            client_id: 'myclientid',
                                            client_secret: 'mycs',
                                            refresh_token: 'myrt'
                                        }); 

       // Make the API request. The request object is included here as 'resource'.
                                    script.scripts.run({                                
                                        auth:auth,
                                        resource: {
                                            function: 'publicFunction',
                                            parameters:[spreadsheetid],
                                            devMode: true 
                                        },
                                        scriptId: scriptId
                                    }, function (err, resp) {
                                        if (err) {
                         console.log('The API returned an error: ' + err);
                                            return;
                                        }
    var apiresp= resp.response.result;
    console.log('current sheet id : ',apiresp);
                                        }
                                    });
                                }
Here is my google apps script :

function publicFunction(params){

var id  = SpreadsheetApp.openById(params).getSheetId();

 return id; // it is always returning first worksheet Id 

}

I am too much worry about this, please anybody help 
Thanks,



via uday kumar

No comments:

Post a Comment