How to export Google spreadsheet tables to google slides

49 views
Skip to first unread message

かなやん

unread,
Oct 2, 2022, 3:52:02 AMOct 2
to Google Apps Script Community
I would like to ask a question.
(*I am Japanese. Please understand that the text may be incorrect because I am using a translation)
I would like to use google apps script to export a colored table created in google spreadsheet to google slides at an arbitrary time.
Since I want to export it in colored form, I cannot use the method of exporting as a graph, so I wanted to know about other means.
I would be happy to use an API or other means that costs as little as possible.
Please let me know.

Translated with www.DeepL.com/Translator (free version)

Edward Ulle

unread,
Oct 2, 2022, 10:57:06 AMOct 2
to Google Apps Script Community
Here is an example of how to copy a table from spreadsheet to slide.  You can explore other formatting options from SpreadsheetApp (https://developers.google.com/apps-script/reference/spreadsheet/) and from SlideApp (https://developers.google.com/apps-script/reference/slides/slides-app).

function myFunction() {
  try {
    let spread = SpreadsheetApp.openById("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
    let sheet = spread.getSheetByName("Sheet1");
    let range = sheet.getDataRange();
    let values = range.getDisplayValues();
    let bColors = range.getBackgrounds();
    let fColors = range.getFontColors();

    let present = SlidesApp.getActivePresentation();
    let slide = present.getSlides()[0];
    let table = slide.insertTable(values.length,values[0].length);
    values.forEach( (row,i) => {
        row.forEach( (text,j) => {
            let cell = table.getCell(i,j)
            cell.getText().setText(text);
            cell.getText().getTextStyle().setForegroundColor(fColors[i][j])
            cell.getFill().setSolidFill(bColors[i][j]);
            cell
          }
        );
      }
    );
  }
  catch(err) {
    console.log(err);
  }
}

Reply all
Reply to author
Forward
0 new messages