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

161
Visualizações
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 à 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