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

118
Visualizações
Would it be possible to create a script which would search and highlight multiple words within a Google doc?

So I would like to be able to have the ability to search up to 30+ phrases within a Google doc. Currently I have to do this process manually with find and replace tool.

But could a script automate this process in someway where it would search for the words and highlight them within the doc for me to review.

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

0

Issue:

If I understand you correctly, you want to highlight (by highlight, I assume you mean changing the background color) certain sentences if they are present in your document.

Solution:

  • For each sentence, use Body.findText(sentence) to find its first occurrence in the document.
  • Retrieve the start and end offset of the resulting RangeElement.
  • Check whether the corresponding element can be edited as text and obtain a text version of it (see editAsText()).
  • Change the background color using setBackgroundColor.

Code sample:

const sentences = ["First sentence", "Second"]; // Your sentences

function highlightSentences() {
  const doc = DocumentApp.getActiveDocument();
  const body = doc.getBody();
  sentences.forEach(sentence => {
    const rangeElement = body.findText(sentence);
    if (rangeElement) {
      const startOffset = rangeElement.getStartOffset();
      const endOffset = rangeElement.getEndOffsetInclusive();
      const element = rangeElement.getElement();
      if (element.editAsText) {
        const textElement = element.editAsText();
        textElement.setBackgroundColor(startOffset, endOffset, "#fcfc03");
      }
    }
  });
}
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