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

257
Visualizações
Return the sheet name when using TextFinder on Google sheets App script

I am searching for a word in a spreadsheet using TextFinder on Google sheets Script.

I would like to have as an output the name of the sheet where the text was found.

Usually they'll only be 1 of this keyword per spreadsheet and for sure only once per sheet.

If found more than 1 in spreadsheet would be nice to have all sheet names returned.

Code:

function TestCMNDH() {
  var source = SpreadsheetApp.openById('SheetID');
  var found = source.createTextFinder('Wordtosearch').matchCase(false).findAll();
  Logger.log(found)
};

Current output: [Range]

Any help would be greatly appreciated! Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could do something like this to get a unique list name of the spreadsheets where the text was found:

function myFunction() {
  var source = SpreadsheetApp.openById('SheetID');
  var foundRange = source.createTextFinder('Wordtosearch').matchCase(false).findAll();

  var sheetNames = foundRange.map(range => range.getSheet().getName());
  var uniqSheetNames = [...new Set(sheetNames)];

  uniqSheetNames.forEach(sheetName => Logger.log(sheetName));
}

What you get as a result of the findAll function is an array of Range.

You can get the Sheet that sheet belongs to using getSheet(), and you can get the name of that sheet using getName()

So I map that array of Range into an array of sheet names:

var sheetNames = foundRange.map(range => range.getSheet().getName());

The following line remove any possible duplicate, and then just log the names in the last line

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