pdf 是从 google 幻灯片创建的,但填充了标记(通过 GAS)

pdf is created from google slide, but with the markers populated (via GAS)

下面的代码基本上将电子表格中的列映射到我在 google 幻灯片上得到的几个标记。 它生成 google 幻灯片模板的副本,用行的数据更新它们,我实际上需要它是 pdf 格式以便稍后通过电子邮件发送。 pdf 文件是在目标文件夹中创建的,文件名正确,但其中的标记是“空的”。稍后,我将不得不删除这些 google 个幻灯片文件,但现在的挑战是正确创建 pdf 文件。

感谢您的宝贵时间。

function mailMerge(templateID,ssID, sheetName, mapped, fileNameData, emailCol, rowLen = "auto"){
  //Properties Services is Google Script Storage. 
  //This clears out the storage. 
  PropertiesService.getScriptProperties().deleteAllProperties();
  
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  //const sheet = SpreadsheetApp.openById(ssID);
  const sheet = ss.getSheetByName("Lista de Participantes");
  
  
  //Get number of rows to process
  rowLen = (rowLen = "auto") ? getRowLen()  : rowLen;
  
  const range = sheet.getRange(7,1,rowLen,sheet.getDataRange().getNumColumns());
  const matrix = range.getValues();

  const fileNameRows = getFileNameRows()
  

  for(let i = 1; i < rowLen; i++){
    if (matrix[i][1] == true && matrix[i][27] != "Sim") {
    let row = matrix[i];
    //Get the title for the file.
    let fileName = buildFileName(row)    
    
    //Creates a copy of the template file and names it with the current row's details.
    let newDoc = DriveApp.getFileById(templateID).makeCopy(fileName);
    
    //Replaces all the text place markers ({{text}}) with current row information. 
    updateFileData(row, newDoc.getId());
        
    //Save new File ID and email to Properties service.
    PropertiesService.getScriptProperties()
                     .setProperty(newDoc.getId(),row[emailCol]);

    // 5. Export the temporal Google Slides as a PDF file.
    newDoc = DriveApp.getFileById(newDoc.getId());
    DriveApp.getFolderById("folder ID").createFile(newDoc.getBlob());
    
    }
    };

除了上面的代码之外,我还在同一个 container/Spreadsheet 中找到了这个脚本文件,我在其中映射了要为其生成 google 幻灯片的数据的列。我将每一列数据称为标记。

/*###################################################################
 * Maps the relationship between the Google Sheet header and its location
 * for each column along with it's corresponding Google Slide Doc template name.
 * 
 * To update change the sheet, col and doc:
 * ***
 * {
 *   sheet: << Your sheet header
 *   col: << The column on the google sheet with the above header
 *   doc: << the corresonding name in double braces {{name}} in your Slide template
 * }
 * ***
 *###################################################################
 */
const mappedDocToSheet = [
  {
    sheet:"Nome",
    col:2,
    doc:"primeiroNome"
  },
  {
    sheet:"Sobrenome",
    col:3,
    doc:"sobrenome"
  },
  {
    sheet:"COD. CERTIFICADO",
    col:9,
    doc:"codigo"
  },
  {
    sheet:"Curso",
    col:10,
    doc:"curso"
  },
];

我相信你的目标和情况如下。

  • 您添加 Google 个幻灯片的值并将其创建为 PDF 数据
  • newDoc 是 Google 幻灯片

为了实现您的目标,请使用saveAndClose。对于您的脚本,请修改如下。

修改后的脚本:

请将以下脚本添加到您的 mailMerge 函数中,如下所示。

// 5. Export the temporal Google Slides as a PDF file.
SlidesApp.openById(newDoc.getId()).saveAndClose();  // <--- Added

参考: