从Google表格数据中自动填充Google表格模板

时间:2019-06-23 15:35:45

标签: javascript google-apps-script google-sheets auto-populate

我想做与基本邮件合并相同的概念,但是要使用2个Google工作表。一个有输入,另一个要填充。 模板:https://docs.google.com/spreadsheets/d/1iArfClgEMfwKQbEV_irwIbVD72hNI0JWCgtlizZKaGg/edit?usp=sharing

数据:https://docs.google.com/spreadsheets/d/1o6Vag8pNhJgKdXK63Ic5sU_UcdbeJGkLOublIuTjOnY/edit?usp=sharing

    function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ 
    {name: "Invoice from selection", functionName: "generateInvoice"},
  ];
  ss.addMenu("Invoice", menuEntries);
}

function generateInvoiceForRow(index) {
  var templateid = "1iArfClgEMfwKQbEV_irwIbVD72hNI0JWCgtlizZKaGg"; // this is the template file id. You can find this in the URL of the google document template. For example, if your URL Looks like this: https://docs.google.com/document/d/1SDTSW2JCItWMGkA8cDZGwZdAQa13sSpiYhiH-Kla6VA/edit, THEN the ID would be 1SDTSW2JCItWMKkA8cDZGwZdAQa13sSpiYhiH-Kla6VA
  var FOLDER_NAME = "NAME OF DESTINATION FOLDER"; // Enter the name of the folder where you want to save your new documents. for example, this could be "Output Folder".

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('inputs');
  var invoice = ss.getSheetId("1iArfClgEMfwKQbEV_irwIbVD72hNI0JWCgtlizZKaGg")
  if (index===1) }
  else {
    var Name = sheet.getRange('D' + index).getValue(),
        Email = sheet.getRange('C' + index).getValue(),
        Address = sheet.getRange('E' + index).getValue();
    ss.getRangeByName('client').setValue(Name + ' ' + Email+ '\n' + Address);



    appendToDoc(doc, newDoc)

  var usernamefordoctitle = sheet.getRange(2, 1, 1, 1).getValues(); 
  var newDoc = SpreadsheetApp.create(current row " +clientname");
  var file = DriveApp.getFileById(newDoc.getId());
  var folder = DriveApp.getFolderById("1BGzhaYlSIRn2yHOED-U4qO04MDZHmgOc"); // INSERT the destination folder ID. Once again, this can be found in the URL once you have the folder openned in your browser
  folder.addFile(file)
  for (var i in data){
    var row = data[i];

  ;

    doc.saveAndClose()


function onOpen() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var menuEntries = [ 
    {name: "Invoice from selection", functionName: "generateInvoice"},
  ];
  ss.addMenu("Invoice", menuEntries);
}

function generateInvoiceForRow(index) {
  var templateid = "1iArfClgEMfwKQbEV_irwIbVD72hNI0JWCgtlizZKaGg"; // this is the template file id. You can find this in the URL of the google document template. For example, if your URL Looks like this: https://docs.google.com/document/d/1SDTSW2JCItWMGkA8cDZGwZdAQa13sSpiYhiH-Kla6VA/edit, THEN the ID would be 1SDTSW2JCItWMKkA8cDZGwZdAQa13sSpiYhiH-Kla6VA
  var FOLDER_NAME = "NAME OF DESTINATION FOLDER"; // Enter the name of the folder where you want to save your new documents. for example, this could be "Output Folder".

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('inputs');
  var invoice = ss.getSheetId("1iArfClgEMfwKQbEV_irwIbVD72hNI0JWCgtlizZKaGg")
  if (index===1) }
  else {
    var Name = sheet.getRange('D' + index).getValue(),
        Email = sheet.getRange('C' + index).getValue(),
        Address = sheet.getRange('E' + index).getValue();
    ss.getRangeByName('client').setValue(Name + ' ' + Email+ '\n' + Address);



    appendToDoc(doc, newDoc)

  var usernamefordoctitle = sheet.getRange(2, 1, 1, 1).getValues(); 
  var newDoc = SpreadsheetApp.create(current row " +clientname");
  var file = DriveApp.getFileById(newDoc.getId());
  var folder = DriveApp.getFolderById("1BGzhaYlSIRn2yHOED-U4qO04MDZHmgOc"); // INSERT the destination folder ID. Once again, this can be found in the URL once you have the folder openned in your browser
  folder.addFile(file)
  for (var i in data){
    var row = data[i];

  ;

    doc.saveAndClose()
    newDoc.saveAndClose()


    DriveApp.getFileById(docid).setTrashed(true);

  }
  ss.toast("Templates has been complied.);
}
}

0 个答案:

没有答案