Image 在来自谷歌电子表格的谷歌文档(或pdf)中插入图像?

Image 在来自谷歌电子表格的谷歌文档(或pdf)中插入图像?,image,url,google-sheets-api,google-docs,google-docs-api,Image,Url,Google Sheets Api,Google Docs,Google Docs Api,我有谷歌电子表格和一些图纸和线条 我把我的谷歌电子表格的每一行原始数据,根据谷歌文档模板生成一个pdf 在一个raw中,我将图片中的url存储在googledrive中,我想将图片显示到我的pdf中,但我没有成功,我只能显示url链接,我尝试了这个tuto(),但我没有成功 我试图将图像显示到电子表格的单元格中,并将其发送到我的pdf中,但它也不起作用,它显示“Cellimage”文本,但没有什么效果 请问有人有什么想法吗?非常感谢 /* PDF创建者-通过电子邮件发送所有回复 =======

我有谷歌电子表格和一些图纸和线条

我把我的谷歌电子表格的每一行原始数据,根据谷歌文档模板生成一个pdf

在一个raw中,我将图片中的url存储在googledrive中,我想将图片显示到我的pdf中,但我没有成功,我只能显示url链接,我尝试了这个tuto(),但我没有成功

我试图将图像显示到电子表格的单元格中,并将其发送到我的pdf中,但它也不起作用,它显示“Cellimage”文本,但没有什么效果

请问有人有什么想法吗?非常感谢


/*
PDF创建者-通过电子邮件发送所有回复
=================================
当您单击“创建PDF>为每行创建PDF”时,此脚本
为附加的GSheet中的每一行构造PDF。价值观
“文件名”列用于命名文件,如果有
价值-在“电子邮件”列中通过电子邮件发送给收件人。
*/
//配置
// ------
// 1. 创建一个GDoc模板并将ID放在这里
var TEMPLATE_ID='谷歌文档中的我的模板ID'
// 2. 您可以在此处指定新PDF文件的名称,或保留为空以使用
//模板的名称或在图纸中指定文件名
变量PDF文件名=“”
// 3. 如果指定了电子邮件地址,您可以通过电子邮件发送PDF
var EMAIL_SUBJECT=‘合同关系’
var EMAIL_BODY='您好,安装控制记录套件,veuillez trouver ci联合公司PDF版。你有什么好意吗?谢谢
// 4. 如果此处指定了文件夹ID,则PDF将位于此处
var RESULTS\u FOLDER\u ID='我发送PDF的文件夹'
//常数
// ---------
//可以提取特定的列值
var文件名列名='data Nom'
var EMAIL\u COLUMN\u NAME='数据电子邮件'
//用于任何日期的格式
变量日期格式='dd/MM/yyyy';
/**
*电子表格打开的Eventhandler-添加菜单。
*/
函数onOpen(){
电子表格应用程序
.getUi()
.createMenu(“[Create PDF]”)
.addItem('为每行创建PDF','CreatePDF')
.addToUi()
}//onOpen()
/**  
*从活动工作表中的每一行获取字段
*并且,使用谷歌文档模板,用这些创建一个PDF文档
*替换模板中键的字段。钥匙已识别
*两边都有一个%s,例如%Name%。
*/
函数createPdfs(){
var ui=SpreadsheetApp.getUi()
如果(模板ID==''){
ui.alert('code.gs'中需要定义模板\u ID')
返回
}
//设置文档和电子表格访问权限
var templateFile=DriveApp.getFileById(模板ID)
var activeSheet=SpreadsheetApp.getActiveSheet()
var allRows=activeSheet.getDataRange().getValues()
var headerRow=allRows.shift()
//为每行创建一个PDF
allRows.forEach(函数(行){
createPdf(模板文件,标题,行)
//私人职能
// ----------------
/**
*创建PDF
*
*@param{File}templateFile
*@param{Array}headerRow
*@param{Array}activeRow
*/
函数createPdf(templateFile、headerRow、activeRow){
var头值
活性细胞
变量ID=null
var recipient=null
var复制文件
var numberOfColumns=头错误长度
var copyFile=templateFile.makeCopy()
var copyId=copyFile.getId()
var copyDoc=DocumentApp.openById(copyId)
var copyBody=copyDoc.getActiveSection()
//将键替换为电子表格值并查找一对
//特定价值
对于(var columndex=0;columndex
不幸的是,从你的问题来看,我无法想象你的目标。我为我糟糕的英语水平道歉。为了正确理解您的问题,您能否提供您当前的脚本、脚本当前版本的解释以及您期望的示例输入和输出情况?H
/*

PDF Creator - Email all responses
=================================

When you click "Create PDF > Create a PDF for each row" this script 
constructs a PDF for each row in the attached GSheet. The value in the 
"File Name" column is used to name the file and - if there is a 
value - it is emailed to the recipient in the "Email" column.



*/

// Config
// ------


// 1. Create a GDoc template and put the ID here

var TEMPLATE_ID = 'MY TEMPLATE ID IN GOOGLE DOCS'



// 2. You can specify a name for the new PDF file here, or leave empty to use the 
// name of the template or specify the file name in the sheet

var PDF_FILE_NAME = ''

// 3. If an email address is specified you can email the PDF

var EMAIL_SUBJECT = 'Rapport de contrôle'
var EMAIL_BODY = 'Bonjour, suite au contrôle de raccordement de votre installation, veuillez trouver ci-joint le compte-rendu en version PDF. Vous en souhaitant une bonne réception.Bien Cordialement. '

// 4. If a folder ID is specified here this is where the PDFs will be located

var RESULTS_FOLDER_ID = 'FOLDER WHERE I SEND MY PDF'

// Constants
// ---------

// You can pull out specific columns values 
var FILE_NAME_COLUMN_NAME = 'data-Nom'
var EMAIL_COLUMN_NAME = 'data-Email'

// The format used for any dates 
var DATE_FORMAT = 'dd/MM/yyyy';

/**
 * Eventhandler for spreadsheet opening - add a menu.
 */

function onOpen() {

  SpreadsheetApp
    .getUi()
    .createMenu('[ Create PDFs ]')
    .addItem('Create a PDF for each row', 'createPdfs')
    .addToUi()

} // onOpen()

/**  
 * Take the fields from each row in the active sheet
 * and, using a Google Doc template, create a PDF doc with these
 * fields replacing the keys in the template. The keys are identified
 * by having a % either side, e.g. %Name%.
 */

function createPdfs() {

  var ui = SpreadsheetApp.getUi()

  if (TEMPLATE_ID === '') {    
    ui.alert('TEMPLATE_ID needs to be defined in code.gs')
    return
  }

  // Set up the docs and the spreadsheet access

  var templateFile = DriveApp.getFileById(TEMPLATE_ID)
  var activeSheet = SpreadsheetApp.getActiveSheet()
  var allRows = activeSheet.getDataRange().getValues()
  var headerRow = allRows.shift()

  // Create a PDF for each row

  allRows.forEach(function(row) {
  
    createPdf(templateFile, headerRow, row)
    
    // Private Function
    // ----------------
  
    /**
     * Create a PDF
     *
     * @param {File} templateFile
     * @param {Array} headerRow
     * @param {Array} activeRow
     */
  
    function createPdf(templateFile, headerRow, activeRow) {
      
      var headerValue
      var activeCell
      var ID = null
      var recipient = null
      var copyFile
      var numberOfColumns = headerRow.length
      var copyFile = templateFile.makeCopy()      
      var copyId = copyFile.getId()
      var copyDoc = DocumentApp.openById(copyId)
      var copyBody = copyDoc.getActiveSection()
           
      // Replace the keys with the spreadsheet values and look for a couple
      // of specific values
     
      for (var columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
        
        headerValue = headerRow[columnIndex]
        activeCell = activeRow[columnIndex]
        activeCell = formatCell(activeCell);
                
        copyBody.replaceText('<<' + headerValue + '>>', activeCell)
        
        if (headerValue === FILE_NAME_COLUMN_NAME) {
        
          ID = activeCell
          
        } else if (headerValue === EMAIL_COLUMN_NAME) {
        
          recipient = activeCell
        }
      }
      
      // Create the PDF file
        
      copyDoc.saveAndClose()
      var newFile = DriveApp.createFile(copyFile.getAs('application/pdf'))  
      copyFile.setTrashed(true)
    
      // Rename the new PDF file
    
      if (PDF_FILE_NAME !== '') {
      
        newFile.setName(PDF_FILE_NAME)
        
      } else if (ID !== null){
    
        newFile.setName(ID)
      }
      
      // Put the new PDF file into the results folder
      
      if (RESULTS_FOLDER_ID !== '') {
      
        DriveApp.getFolderById(RESULTS_FOLDER_ID).addFile(newFile)
        DriveApp.removeFile(newFile)
      }

      // Email the new PDF

      if (recipient !== null) {
      
        MailApp.sendEmail(
          recipient, 
          EMAIL_SUBJECT, 
          EMAIL_BODY,
          {attachments: [newFile]})
      }
    
    } // createPdfs.createPdf()

  })

  ui.alert('New PDF files created')

  return
  
  // Private Functions
  // -----------------
  
  /**
  * Format the cell's value
  *
  * @param {Object} value
  *
  * @return {Object} value
  */
  
  function formatCell(value) {
    
    var newValue = value;
    
    if (newValue instanceof Date) {
      
      newValue = Utilities.formatDate(
        value, 
        Session.getScriptTimeZone(), 
        DATE_FORMAT);
        
    } else if (typeof value === 'number') {
    
      newValue = Math.round(value * 100) / 100
    }
    
    return newValue;
        
  } // createPdf.formatCell()
  
} // createPdfs()