Home > other >  How to convert my google spreadsheet container-bound script to code standalone script?
How to convert my google spreadsheet container-bound script to code standalone script?

Time:09-16

I have a working code that bound into a spreadsheet. I want to run this script to other spreadsheet automatically without me opening the spreadsheet and opening the apps script editor one by one. I have read online that I must change my script into standalone script. Here is my code :

function hideRows() {
  let sh = SpreadsheetApp.getActiveSpreadsheet();
  let ss = sh.getSheetByName("Invoice");
  let r = ss.getRange("A2:G23");
  let data = r.getValues();
  //console.log(data);
  for (var i = 0; i < data.length; i  ) {
    if (data[i].filter(String).length == 0) {
      ss.hideRows(i   2);
    }
  }
}

Is there anything I can do? my coding skill is below basic, and sorry for my poor english.

CodePudding user response:

You can open a new script from https://script.new and paste your Apps Script code in the editor.

Since this is a standalone script, the following line needs to be replaced.

let sh = SpreadsheetApp.getActiveSpreadsheet();

It should be replaced with the URL or ID of the Google Sheet.

const ssId = "1234...";
let sh = SpreadsheetApp.openById(ssId);
  • Related