Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda