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

155
Vistas
Add Text at Cursor and Set Headings using Google Apps Script in Docs

Trying to insert specific text at my cursor to a Google Doc via a custom menu created via Google Apps Script. I am then trying to format that text to specific headings, body, etc. The below code is not working and is inserting all text with the same format as the surrounding text within the Google Doc. I have tried a number of different methods to accomplish this but am hoping for some help or tips!

Custom Google Doc Menu

Expected Result

Actual Result

function menuItem12() {
  var cursor = DocumentApp.getActiveDocument().getCursor();
 
  var headerAttr = {}
  headerAttr[DocumentApp.Attribute.HEADING] = DocumentApp.ParagraphHeading.HEADING2;

  var bodyAttr = {}
  bodyAttr[DocumentApp.Attribute.HEADING] = DocumentApp.ParagraphHeading.NORMAL;
  
  var text = cursor.insertText("Resource Link");
  text.setLinkUrl("https://www.google.com");

  var header = cursor.insertText("Resource Heading\n");
  header.editAsText().setAttributes(0, header.getText().length, headerAttr);


  DocumentApp.getUi().alert('Resources added.');
  
  }

about 4 years ago · Juan Pablo Isaza
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