使用Apps脚本将Google工作表范围导出为pdf并将pdf存储在驱动器中 [英] Export a Google sheet range as pdf using Apps script and store the pdf in drive

查看:70
本文介绍了使用Apps脚本将Google工作表范围导出为pdf并将pdf存储在驱动器中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要一些帮助,希望您能帮助我:)

need some help and hope you can help me :)

我有一个Google电子表格文档,并且需要针对每个脚本执行一些操作:工作表:"Sheet1"范围:"A1:J39"

I have a google spreadsheet document and need to do some actions per script: Sheet: "Sheet1" Range: "A1:J39"

  1. 使用设置(横向,完美宽度)打印出来

  1. print out with settings (landscape, perfect width)

另存为PDF文档到共享的Google驱动器的文件夹中(相同的设置,例如1)

save as PDF document in a folder in a shared google drive (same settings like no 1)

每封邮件将PDF文件发送到另一页中列出的地址

send PDF file per mail to adresses which listed in an other sheet

希望您能帮助我解决这个问题....

hope you can help me with this problem....

thx

推荐答案

我正在提供以下代码,该代码用于将整张表格发送为PDF.您可以对其稍加修改,以

I'm giving below code I use to send a full sheet as PDF. You can modify it slightly to

1.隐藏不需要的行和列2.包括PDF导出选项

1.Hide unwanted rows and columns 2.Include PDF export options

function send_sheet(){
  var today=new Date();
  var ss = SpreadsheetApp.getActiveSpreadsheet(); 
  var ltrsht = ss.getSheetByName("Letter");    
  var sheets=SpreadsheetApp.getActiveSpreadsheet().getSheets();
  for(var i =0;i<sheets.length;i++){
    if(sheets[i].getName()!="Letter"){ sheets[i].hideSheet() }
    }
    var pdf = DriveApp.getFileById(ss.getId());
    var theBlob = pdf.getBlob().getAs('application/pdf').setName(ltrsht.getRange("C16").getValue()+".pdf");
    var folderID = ""; // Folder id to save in a folder
    var folder = DriveApp.getFolderById(folderID);
    var newFile = folder.createFile(theBlob);
    var body = 'Dear ' + ltrsht.getRange("C16").getValue() +',\n\nPL. find your ' + ltrsht.getRange("C11").getValue() +' enclosed.\n\nHRD Megawin Switchgear';
    GmailApp.sendEmail(ltrsht.getRange("E17").getValue(), ltrsht.getRange("C11").getValue() + " from Megawin HRD", body, {attachments: [theBlob]});
    var empsht = ss.getSheetByName("Emp");  
    empsht.showSheet();
    ltrsht.hideSheet();

}



首先,您必须隐藏目标工作表以外的所有工作表隐藏不需要的行和列转换成PDF保存在文件夹中发送到存储了一些单元格的电子邮件ID

First you have to hide all sheets other than the target sheet Hide unwanted rows and columns Convert to PDF Save in folder Send to email id which is stored some cell

请参见下文如何设置PDF格式

See below how to format the PDF

https://support.google.com/docs/thread/3457043?hl = zh_CN

这篇关于使用Apps脚本将Google工作表范围导出为pdf并将pdf存储在驱动器中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆