Export spreadsheet data to a Google presentation

by Viktor H. Morales

JavaScript

/**
 * VER ARTÍCULO EN MI SITIO WEB
 * https://viktormorales.com/diseno-y-desarrollo-web/exportar-datos-de-hoja-de-calculo-a-una-presentacion-de-google/
 */

/**
 * onOpen()
 * This function is triggered when the current Spreadsheet is open
 */
function onOpen() {
  createCustomMenu();
}

/**
 * createCustomMenu()
 * Create a custom menu on the current Spreadsheet
 */
function createCustomMenu() {
  var menu = SpreadsheetApp.getUi().createMenu("Crear voucher");
   menu.addItem("Exportar a PDF", "createVoucher");
   menu.addToUi();
}

/**
 * getFilesVariables()
 * Set the IDs of the files and folders to work with
 */
function getFilesVariables() {
  const filesId = {
    "presentation": "PRESENTATION_ID", // Change this value to the Google Slides ID
    "folder": "FOLDER_ID", // Change this value to the Folder ID where to save the PDF exported presentation file
    "sheetName": "TAB NAME" // Change this value to the tab name of the presentation
  }
  return filesId;
}

/**
 * createVoucher()
 * This function is used to create the voucher
 */
function createVoucher() {
  const filesVar = getFilesVariables();

  // Get data from Google Sheets
  const sheet = SpreadsheetApp.getActiveSpreadsheet();
  const sheetName = filesVar["sheetName"];
  const tab = sheet.getSheetByName(sheetName);

  // Access an slide presentation
  const presentation = SlidesApp.openById(filesVar["presentation"]);
  const presentationName = presentation.getName();

  // Get the last non-empty row values
  const lastRow = getLastRowInColumn(tab);
  const getRow = getRowData(tab, lastRow);

  // If there is data on the sheet, continue with the process
  if (lastRow > 1) {
    // Mensaje
    SpreadsheetApp.getActive().toast("Aguarde mientras se crea el archivo PDF");

    // Create a COPY of the original slide presentation
    const copy = DriveApp.getFileById(filesVar["presentation"]).makeCopy(`Copy ${presentationName}`);
    const...