我是谷歌應用腳??本的新手,不知道是否可能。需要一個腳本將定義的范圍(A1:I5)作為 PDF 發送到電子郵件(在 K2、cc 和 bcc 中定義的電子郵件地址在腳本中定義)。
SS 鏈接:https ://docs.google.com/spreadsheets/d/1tmnDOMyupjeO8d65qHQsxb5KrrKeq7pMYIE8h2VmEJ4/edit#gid=0
提前致謝。
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您想將“Sheet1”中的“A1:I5”范圍匯出為 PDF 檔案,并從單元格“K2”中檢索電子郵件地址。而且,您想將它們作為電子郵件發送。
- 您要在腳本中宣告
cc和。bcc
使用此資訊時,將“Sheet1”中的“A1:I5”范圍匯出為 PDF 資料的端點如https://docs.google.com/spreadsheets/d/${ss.getId()}/export?format=pdf&range=A1:I5&gid=${sheet.getSheetId()}. 使用此端點時,示例腳本如下。
示例腳本:
function myFunction() {
const cc = ""; // Please set cc.
const bcc = ""; // Please set bcc.
// Retrieve Spreadsheet and Sheet objects.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName("Sheet1");
// Retrieve PDF blob.
const url = `https://docs.google.com/spreadsheets/d/${ss.getId()}/export?format=pdf&range=A1:I5&gid=${sheet.getSheetId()}`;
const pdfBlob = UrlFetchApp.fetch(url, { headers: { authorization: "Bearer " ScriptApp.getOAuthToken() } }).getBlob();
// Send an email using email from cell "K2".
const email = sheet.getRange("k2").getValue();
MailApp.sendEmail({
to: email,
cc: cc || null,
bcc: bcc || null,
subject: "sample subject",
body: "sample body",
attachments: [pdfBlob],
});
// DriveApp.getFiles() // This comment line is used for automatically detecting a scope of "https://www.googleapis.com/auth/drive.readonly". In order to export PDF data, I thought that this scope might be required to be included.
}
- 運行此腳本時,會從“Sheet1”中的單元格“A1:I5”中檢索 PDF 資料,并使用從“K2”中檢索到的電子郵件地址發送電子郵件。PDF 用作附件檔案。
參考:
- 有關如何將 Google 作業表匯出為各種格式的示例,包括大多數 PDF 選項
- 類 MailApp 的 sendEmail(message)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/485784.html
