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

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

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 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