我需要有人帮助我为此工作表https://docs.google.com/spreadsheets/d/14JgHIvp8aEyDaHYcExWWQM9E0lTdg0W5Jb-UzWIHHX0/edit#gid=0 Sheet1编写脚本,并且数据的行数每月都会上下波动。
我需要一个脚本是日期触发的,我可以设置日期触发器,但是我想要的是在每个月的第一天,我需要脚本将Sheet1上的数据提取出来(行数不同)并使用该数据创建PDF 。然后使用该月的名称和一些文字将PDF保存到我的云端硬盘中,例如,本月看起来像“ May Form Data”,然后将该PDF通过电子邮件发送给我。因此,在下个月的1月1日,它将创建新的PDF并将其命名为“ June Form Data”并通过电子邮件发送给我。这会每月发生一次,因为工作表上的数据每个月都会发生变化。表格中的数据将与其他表格中的公式一起输入。
答案 0 :(得分:0)
每月报告
您提供:触发器,SpreadsheetId,SheetName,您的电子邮件地址和FolderId。
function firstDayOfTheMonthReport() {
var ss=SpreadsheetApp.openById('SpreadsheetId');
var shts=ss.getSheets();
for(var i=0;i<shts.length;i++) {
if(shts[i].getName()!='SheetName') {
shts[i].hideSheet();
}
}
var fileid=ss.getId();
var folder=DriveApp.getFolderById('FolderId');
var name=Utilities.formatString('%s Form Data', Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MMM"));
var fileblob=DriveApp.getFileById(fileid).getBlob().getAs('application/pdf').setName(name);
var file=folder.createFile(fileblob);
GmailApp.sendEmail('your email', 'Monthly Report', 'Report in Attachments', {attachments:[file.getAs(MimeType.PDF)]});
}
您请求的版本,也许还有更多。
在运行脚本之前,请先阅读这些说明
脚本:
function firstDayOfTheMonthReport1() {
var ss=SpreadsheetApp.openById('SpreadsheetId');//You have to provide this Spreadsheet Id
var shts=ss.getSheets();
var pdfshtsA=['Sheet1'];//You have to put sheetnames that you want included in pdf in here you can included hidden sheets if you wish they will hidden again after the pdfs are created and the email is sent.
var visshtsA=[];//The script will put current visible sheets that are not in the above list
var hidshtsA=[];//The script will put sheets that are in pdfshtsA but are currently hidden so that they can be in the pdf and then hidden afterward
for(var i=0;i<shts.length;i++) {
if(pdfshtsA.indexOf(shts[i].getName()) == -1) {
if(!shts[i].isSheetHidden()) {
visshtsA.push(shts[i].getName());
shts[i].hideSheet();
}
}else{
if(shts[i].isSheetHidden()) {
hidshtsA.push(shts[i].getName());
shts[i].showSheet();
}
}
}
var fileid=ss.getId();
var folder=DriveApp.getFolderById('FolderId');//You need to provide the FolderId
var name=Utilities.formatString('%s Form Data', Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "MMM"));
var fileblob=DriveApp.getFileById(fileid).getBlob().getAs('application/pdf').setName(name);
var file=folder.createFile(fileblob);
GmailApp.sendEmail('your email', 'Monthly Report', 'Report in Attachments', {attachments:[file.getAs(MimeType.PDF)]});
for(var i=0;i<visshtsA.length;i++) {
ss.getSheetByName(visshtsA[i]).showSheet();
}
for(var i=0;i<hidshtsA.length;i++) {
ss.getSheetByName(hidshtsA[i]).hideSheet();
}
}