Automate Google Slides Presentations with Apps Script

Generating slide decks from data is one of the most impressive automations you can build with Apps Script. Whether it's weekly dashboards, client reports, or personalised presentations — SlidesApp handles it all.

Open a presentation

// Bound to a Slides file const presentation = SlidesApp.getActivePresentation(); // By ID const presentation = SlidesApp.openById('YOUR_PRESENTATION_ID');

Read slide content

function readSlides() { const presentation = SlidesApp.getActivePresentation(); const slides = presentation.getSlides(); slides.forEach((slide, i) => { Logger.log(`Slide ${i + 1}:`); slide.getShapes().forEach(shape => { if (shape.getText) { Logger.log(' ' + shape.getText().asString().trim()); } }); }); }

Replace text placeholders in a template

This is the most common pattern — create a template slide deck with {{placeholders}} and fill them in:

function fillTemplatePlaceholders() { const TEMPLATE_ID = 'YOUR_TEMPLATE_PRESENTATION_ID'; const FOLDER_ID = 'YOUR_OUTPUT_FOLDER_ID'; const data = { '{{client_name}}': 'Acme Corp', '{{month}}': 'March 2025', '{{revenue}}': '$124,500', '{{growth}}': '+12%', }; const templateFile = DriveApp.getFileById(TEMPLATE_ID); const copy = templateFile.makeCopy('Report - Acme Corp', DriveApp.getFolderById(FOLDER_ID)); const presentation = SlidesApp.openById(copy.getId()); presentation.getSlides().forEach(slide => { slide.getShapes().forEach(shape => { if (!shape.getText) return; Object.entries(data).forEach(([placeholder, value]) => { shape.getText().replaceAllText(placeholder, value); }); }); }); presentation.saveAndClose(); Logger.log('Presentation created: ' + copy.getUrl()); }

Add a new slide with text

function addSlide() { const presentation = SlidesApp.getActivePresentation(); const slide = presentation.appendSlide(SlidesApp.PredefinedLayout.TITLE_AND_BODY); const shapes = slide.getShapes(); // Title shapes[0].getText().setText('Q1 Results'); shapes[0].getText().getTextStyle().setBold(true).setFontSize(32); // Body shapes[1].getText().setText('Revenue: $500k\nNew Customers: 42\nChurn Rate: 2.1%'); }

Create a chart slide from Sheets data

function addChartFromSheet() { const presentation = SlidesApp.getActivePresentation(); const sheet = SpreadsheetApp.openById('YOUR_SHEET_ID').getSheetByName('Charts'); const charts = sheet.getCharts(); if (charts.length === 0) { Logger.log('No charts found in sheet.'); return; } const slide = presentation.appendSlide(SlidesApp.PredefinedLayout.BLANK); // Embed the first chart slide.insertSheetsChart(charts[0], 50, 50, 600, 350); Logger.log('Chart added to slide.'); }

Export presentation to PDF

function exportToPdf() { const presentationId = SlidesApp.getActivePresentation().getId(); const file = DriveApp.getFileById(presentationId); const pdfBlob = file.getAs('application/pdf').setName('Presentation.pdf'); // Save PDF to Drive const outputFolder = DriveApp.getRootFolder(); const pdfFile = outputFolder.createFile(pdfBlob); Logger.log('PDF saved: ' + pdfFile.getUrl()); // Or email it GmailApp.sendEmail('[email protected]', 'Your Report', 'See attached.', { attachments: [pdfBlob], }); }

Generate a slide deck for each row in a Sheet

function generateDeckPerRow() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const data = sheet.getDataRange().getValues(); const headers = data[0]; const rows = data.slice(1); rows.forEach(row => { const values = {}; headers.forEach((h, i) => { values[`{{${h}}}`] = row[i]; }); const templateFile = DriveApp.getFileById('YOUR_TEMPLATE_ID'); const copy = templateFile.makeCopy(`Report - ${values['{{name}}'] || 'Client'}`); const presentation = SlidesApp.openById(copy.getId()); presentation.getSlides().forEach(slide => { slide.getShapes().forEach(shape => { if (!shape.getText) return; Object.entries(values).forEach(([k, v]) => { shape.getText().replaceAllText(k, String(v)); }); }); }); presentation.saveAndClose(); }); }

Tips

  • replaceAllText() is case-sensitive and replaces all instances across all slides.
  • presentation.saveAndClose() is important when running from a standalone script — changes may not persist otherwise.
  • Slides created from appendSlide() use the presentation's theme by default.
  • For pixel-perfect layouts, use shape.setLeft(), shape.setTop(), shape.setWidth(), shape.setHeight() to position elements precisely (values are in points).