Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda