gpt4 book ai didi

google-apps-script - 精确的附件扩展名.PDF

转载 作者:行者123 更新时间:2023-12-01 10:05:58 24 4
gpt4 key购买 nike

该代码已发送带有附件的电子邮件,但未显示扩展名。

另外,您能否解释一下如何将附件命名为这种模式:

Pré-emploi-CandidateName.PDF

我试图在“var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");”这一行上更改名称
另外,我尝试在此行的末尾添加var CandidateName

var blob = newSpreadsheet.getAs('application/pdf').setName(spreadsheet.getName()+ " - ".CandidateName);
function emailAsPDF() {
var emailAddress=Session.getActiveUser().getEmail();
var mess="Voulez-vous envoyer votre rapport à l'adresse : " + emailAddress;
var ans= Browser.msgBox("Courriel", mess, Browser.Buttons.YES_NO);
if (ans===Browser.Buttons.NO){return;}
var mess="Votre rapport a été envoyé à l'adresse : " + emailAddress;
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheetByName("Recherche");
//var range = sheet.getActiveCell();
var CandidateName=ss.getRangeByName("Nom.Candidat").getValue();
var emailSubject="Vérifications pré-emploi complétées" +" - "+ CandidateName;
var emailMessage="Bonjour," + "\n\n" + "J’ai le plaisir de vous informer que les vérifications sont complétées pour le candidat indiqué au tableau de résultats pré-emploi suivant:" + "\n\n" + "Bonne journée !";
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();//.getSheetByName("Formation");
var sheet=spreadsheet.getSheetByName("Recherche");
var newSpreadsheet = SpreadsheetApp.create("Spreadsheet to export");
sheet.copyTo(newSpreadsheet);
var sheetNames=newSpreadsheet.getSheets();
newSpreadsheet.deleteActiveSheet();
var blob = newSpreadsheet.getAs('application/pdf').setName(spreadsheet.getName());
var folderID = parentFolder(); // Folder id to save the PDF
Logger.log(folderID);
var folder = DriveApp.getFolderById(folderID);
var pdfFile = folder.createFile(blob);
MailApp.sendEmail(emailAddress, emailSubject, emailMessage,{attachments:[pdfFile]});
//DriveApp.getFileById(pdfFile.getId()).setTrashed(true);
DriveApp.getFileById(newSpreadsheet.getId()).setTrashed(true);
DriveApp.getFileById(pdfFile.getId()).setTrashed(true);
Browser.msgBox("Courriel", mess, Browser.Buttons.OK);
}


function parentFolder() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var file = DriveApp.getFileById(ss.getId());
var ParentFolder= file.getParents();
while ( ParentFolder.hasNext() ) {
var folder = ParentFolder.next();
folderID=folder.getId();
Logger.log(folderID);
}
return folderID;
}

function test() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var file = DriveApp.getFileById(ss.getId());
var ParentFolder= file.getParents();
var folder = ParentFolder.next();
Logger.log(folder);
// while ( ParentFolder.hasNext() ) {
// var folder = ParentFolder.next();
// folderID=folder.getId();
// Logger.log(folderID);
// }
// return folderID;
}

我希望收到这样命名的PDF附件:
Pré-emploi-候选人姓名
另外,如何更改文档方向?

如果您需要访问该文件,请问我。

最佳答案

回答:
您无需在创建时设置blob的名称,而需要在创建时设置文件的名称。
码:

function emailPDF() {
// previous code...
var blob = newSpreadsheet.getAs('application/pdf').setName(spreadsheet.getName());
// code...
var pdfFile = folder.createFile(blob);
}
需要更改为:
function emailPDF() {
// previous code...
var blob = newSpreadsheet.getAs('application/pdf');
// code...
var pdfName = spreadsheet.getName() + " - " + CandidateName + '.pdf';
var pdfFile = folder.createFile(blob).setName(pdfName);
}

关于google-apps-script - 精确的附件扩展名.PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58273518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com