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