Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Extend seach range for all sheets

I am using this script and an input form to search a Google spreadsheet, this script has a range of one sheet,i.e. Data , but I need to extend my range to all sheets in the same spreadsheet, any ideas?

function doGet(e) {
  return HtmlService.createTemplateFromFile("Index").evaluate()
    .setTitle("WebApp: Search By Password")
    .addMetaTag('viewport', 'width=device-width, initial-scale=1')
    .setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}

/* PROCESS FORM */
function processForm(formObject) {
  var concat = formObject.searchtext + formObject.searchtext2;
  var result = "";
  if (concat) {//Execute if form passes search text
    result = search(concat);
  }
  return result;
}

//SEARCH FOR MATCHED CONTENTS ;
function search(searchtext) {
  var spreadsheetId = ' '; //** CHANGE !!!!
  var sheetName = "Data"
  var range = SpreadsheetApp.openById(spreadsheetId).getSheetByName(sheetName).getDataRange();
  var data = range.getValues();
  var ar = [];
  data.forEach(function (f) {
    if (~[f[8]].indexOf(searchtext)) {
      ar.push([f[2], f[3], f[4], f[5], f[6], f[7]]);
    }
  });
  return ar;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe your goal is as follows.

  • You want to search for a text from all sheets of a Google Spreadsheet.
  • You want to achieve this by modifying the script in your question.

In this case, I would like to propose modifying the function search as follows.

Modified script:

function search(searchtext) {
  return SpreadsheetApp
    .getActiveSpreadsheet()
    .getSheets()
    .flatMap(s =>
      s
        .getDataRange()
        .getValues()
        .filter(r => r[8] && r[8].includes(searchtext))
        .map(([,,c,d,e,f,g,h]) => [c,d,e,f,g,h])
    );
}

Note:

  • When you modified the Google Apps Script, please modify the deployment as a new version. By this, the modified script is reflected in Web Apps. Please be careful about this.
  • You can see the detail of this in the report of "Redeploying Web Apps without Changing URL of Web Apps for new IDE".

References:

  • getSheets()
  • filter()
  • map()
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!