有没有一种方法可以自动打印Google表格中的一系列PDF?

时间:2019-12-10 20:06:56

标签: google-apps-script google-sheets

寻找一种获取下面的函数来复制值的方法,而不仅仅是公式。我认为“ copyPasteType”问题不起作用,因为当copyTo在工作表上时,它不能接受更多参数吗?

我很想自动遍历整个列表,以打印约70个项目的不同PDF。向其他创意解决方案开放!

  var targetFolderId = "xxxxxx";
  var targetFolder = DriveApp.getFolderById(targetFolderId);

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('Report');
  var formattedDate = Utilities.formatDate(new Date(), "GMT-7", "yyyy-MM-dd hh:mm:ss");

  //Create Folder for PDFs
  var fld = targetFolder.createFolder(formattedDate);

  for (var i = 46; i < 47; i++) {
    // Iterate first spreadsheet to show new data
    sheet.getRange('I1').setValue([i]);
    SpreadsheetApp.flush();
    Utilities.sleep(1000);

    // Create a new Spreadsheet and copy the current sheet into it.
    var newSpreadsheet = SpreadsheetApp.create("[i]");
    sheet.copyTo(newSpreadsheet);

    //Print PDFs
    newSpreadsheet.getSheetByName('Sheet1').activate();
    newSpreadsheet.deleteActiveSheet();
    var name = sheet.getRange('D1').getValue();
    fld.createFile(newSpreadsheet.getAs('application/pdf')).setName(name);

  }
}

0 个答案:

没有答案