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 fileconst presentation =SlidesApp.getActivePresentation();// By IDconst presentation =SlidesApp.openById('YOUR_PRESENTATION_ID');
functionaddSlide(){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
functionaddChartFromSheet(){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
functionexportToPdf(){const presentationId =SlidesApp.getActivePresentation().getId();const file =DriveApp.getFileById(presentationId);const pdfBlob = file.getAs('application/pdf').setName('Presentation.pdf');// Save PDF to Driveconst outputFolder =DriveApp.getRootFolder();const pdfFile = outputFolder.createFile(pdfBlob);Logger.log('PDF saved: '+ pdfFile.getUrl());// Or email itGmailApp.sendEmail('[email protected]','Your Report','See attached.',{attachments:[pdfBlob],});}
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).