Search code examples
google-apps-script

Select Existing SpreadSheet in Google Appscript


I have an existing spreadsheet(named as 'abc')that i want to activate. I have written codes to open the spreadsheet on the server, but i do not know how to work on this opened spreadsheet such as editing the content. Please advice me how to work on this opened spreadsheet.

I do not need the physical spreadsheet to be opened for viewing. I only need to use codes to further edit the content inside after i opened my existing spreadsheet.

Below are the code:

var student_sheet=SpreadsheetApp.open(DriveApp.getFilesByName('abc').next())
//I want to edit this 'abc' spreadsheet.


Solution

  • You have to set a variable to it and then just update like you would an active spreadsheet.

    function doSomething(){
      var yourSpreadsheet = SpreadsheetApp.openById("???????")// enter your spreadsheet id
      yourSpreadsheet.getRange("A1").setValue("boom"); // sets value in the spreadsheet
      yourSpreadsheet.getRange("B2").clearContent();//deletes values.
    }