google-apps-scriptgoogle-slides

Google Script in Slide - How copy a list of email from a Slide Table to Gmail


I've tried to realize a script but it does not run! The aim of this script is to send slide file by email automatically by clicking in the menu button. In the same time the pdf file is saved automatically. I've developed it and it runs.

I've tried to modify the script in order to scan the emails written in slide 1 and use them to send the email. I've not found the code to do that automatically (between lines 33 to 73). Could you please help me to find the solution? Very big thank you

The Folder where all the files are stored, by clicking here. The script is inside of the slide, by clicking here

A part of the script where are the errors:

// Access to 1st table
  var table1 = slide1.getShapes().find(function (shape) {
    return shape.getShapeType() === SlidesApp.ShapeType.TABLE;
  })[0].getTable();

  // Access to 2nd table
  var table2 = slide1.getShapes().find(function (shape, index) {
    return shape.getShapeType() === SlidesApp.ShapeType.TABLE && index > 0;
  })[0].getTable();

  // Recuperate data from tables 1 & 2
  var data1 = table1.getCell(0, 0).getRange().getValues();
  var data2 = table2.getCell(0, 0).getRange().getValues();

enter code here

enter code here

Solution

  • You have two problems:

    Problem 1: getShapes() returns a collection of Shapes. A Shape doesn't have a getTable() method.

    var table1 = slide1.getShapes().find(function (shape) {
      return shape.getShapeType() === SlidesApp.ShapeType.TABLE;
    })[0].getTable();
    

    To get tables from a slide, call getTables() instead:

    slide1.getTables()
    

    Problem 2: getCell returns a TableCell which doesn't have the getRange() method.

    var data1 = table1.getCell(0, 0).getRange().getValues();
    var data2 = table2.getCell(0, 0).getRange().getValues();
    

    To get the cell value of the first column of the first row, call getText() and asString() instead:

    table1.getCell(1, 0).getText().asString()
    

    Example code

    With that in mind, here's a possible rewrite that collects values from the first column of the tables:

    ..snip
    
    var table1 = slide1.getTables()[0]  // the first table
    var table2 = slide1.getTables()[1]  // the second table
    
    var data1 = []
    var data2 = []
    
    // Loop through the table1 rows
    for (var i = 0; i < table1.getNumRows(); i++) {
      // Add the value found in the first column of the current row
      data1.push(table1.getCell(i, 0).getText().asString())
    }
    
    // Ditto for table2
    for (var i = 0; i < table2.getNumRows(); i++) {
      data2.push(table2.getCell(i, 0).getText().asString())
    }
    
    ...snip
    

    Note: The data1 and data2 variables in this example are one-dimensional arrays. So it doesn't drop in without augmenting code further down your script where it expects a two-dimensional array.