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

365
Visualizações
How to get TextStyles/Attributes (fontColor, fontFamily, etc.) of a Googlesheet cell in AppScript, then set it in a Table

I have a Script in Googlesheets that is suposed to use the sheet as a modifiable template (colors and font should be modifiable), it copies it and paste it as a Table in GoogleSlides. It copies each cell one by one and then it puts it in the slide table cell. My problem is right now i could only get it to copy the text and background color of each cell, not the fontFamily, nor the fontColor.

This is the relevant part of the code:

var slidesPage = SlidesApp.openById(slideID).getSlides()[slideBegin];
var rows = values.length;
var columns = values[0].length;
var table = slidesPage.insertTable(rows, columns);


for (var r = 0; r < rows; r++) {
  for (var c = 0; c < columns; c++) {
    var cell = table.getCell(r, c);
    cell.getText().setText(values[r][c]);
    cell.getFill().setSolidFill(backgrounds[r][c]);
    var alignment;
    switch(horizontalAlignments[r][c]) {
      case "general-left":
        alignment = SlidesApp.ParagraphAlignment.START;
        break;
      case "general-right":
        alignment = SlidesApp.ParagraphAlignment.END;
        break;
      case "center":
        alignment = SlidesApp.ParagraphAlignment.CENTER;
        break;
    }
    //cell.getText().getParagraphStyle().setParagraphAlignment(alignment);
  }
}

I have tried with .getAttributes or stuff like that, but i cant find how is it supposed to go. I know i probably have to set a "var" with the attributes and then add something like cell.getAttributes().setAttributes() but not sure, im completly stuck.

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

0

I know nothing about Slides but in Spreadsheet the thing you want is getRichTextValue() and Class TextStyle

You can get the attributes from a text in a cell about this way:

function myFunction() {
  var ss     = SpreadsheetApp.getActiveSheet();
  var text   = ss.getRange('a1').getRichTextValue() // .getRuns()[0];
  var style  = text.getTextStyle();
  var size   = style.getFontSize()
  var family = style.getFontFamily();
  var color  = style.getForegroundColor();
  var bold   = style.isBold();
  var italic = style.isItalic();
  // etc
  console.log(size, family, bold, italic, color);
}

Update

https://developers.google.com/apps-script/reference/slides/text-range

Surprisingly I see no methods set... in TextRange object in Slides except the setText(text)! There are the get... methods but they're quite useless if you can't apply these attributes.

It looks like this part of Slides App API is not ready yet.

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