Изображение в Google Document не всегда копируется с остальной частью тела документа - PullRequest
1 голос
/ 02 апреля 2020

У меня есть Документ Google в качестве шаблона, который я использую для создания копий файлов из формы Google. В этом шаблоне есть изображение. Бывает, что не все копии получают изображение, но некоторые делают. Это почему? Я попытался сделать медленную обработку, чтобы загрузить изображение в Google Drive, а затем снова вставить его в шаблон. Безуспешно.

Вот код:

function onFormSubmit (e) {
  FormApp.getActiveForm();

  var respostas = e.response.getItemResponses();
  var nome_lavador = respostas[0].getResponse();
  var num_lavagens = respostas[1].getResponse();
  var nome_cliente = respostas[2].getResponse();
  var email_cliente = respostas[3].getResponse();
  var ramal_cliente = respostas[4].getResponse();
  var matricula_cliente = respostas[5].getResponse();
  var arquivos = [];



  //gerar um voucher para cada lavagem adquirida

  for (var v = 0; v<num_lavagens; v++) {
    //número aleatório para o Voucher
    var voucher = Math.floor(Math.random() * Math.floor(1000000));

    var temp = new Date(Date.now());
    var data_voucher = Utilities.formatDate(temp, "GMT-3", "dd/MM/yyyy HH:MM:ss");

    //file is the template file, and you get it by ID
    var file = DriveApp.getFileById('00000...'); 

    //We can make a copy of the template, name it, and optionally tell it what folder to live in
    //file.makeCopy will return a Google Drive file object
    var folder = DriveApp.getFolderById('11111.....')
    var copy = file.makeCopy(voucher, folder); 

    //Once we've got the new file created, we need to open it as a document by using its ID
    var doc = DocumentApp.openById(copy.getId()); 

    //Since everything we need to change is in the body, we need to get that
    var body = doc.getBody(); 

    //Then we call all of our replaceText methods
    body.replaceText('%VOUCHER%', voucher); 
    body.replaceText('%DATA_VOUCHER%', data_voucher); 
    body.replaceText('%NOME_LAVADOR%', nome_lavador); 
    body.replaceText('%NOME_CLIENTE%', nome_cliente); 
    body.replaceText('%MATRICULA_CLIENTE%', matricula_cliente);

    //Juntar o arquivo na lista de anexos do email
    arquivos[v] = doc.getAs(MimeType.PDF);

    //Lastly we save and close the document to persist our changes
    doc.saveAndClose();   


  }


  var recipient = email_cliente;
  var subject = `${nome_cliente}, aqui estão os seus vouchers!`;
  var body = `${nome_cliente}, você antecipou ${num_lavagens} lavagem(ns) para ${nome_lavador}. Obrigado!`;
  MailApp.sendEmail(recipient, subject, body, {attachments: arquivos});  

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...