我發現此代碼可以通過電子郵件將 Google 電子表格的所有選項卡作為 PDF 檔案(一個合并檔案)發送。
function sendReport() {
var message = {
to: "[email protected]",
subject: "Sales Reports",
body: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
name: "Sales",
attachments:[SpreadsheetApp.getActiveSpreadsheet().getAs(MimeType.PDF).setName("sales_report_2021")]
}
MailApp.sendEmail(message);
因此,我只想將“A1”單元格等于“1”的選項卡合并到最終檔案中,并通過電子郵件作為附件發送。
非常感謝你!
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您想創建一個只有當單元格“A1”為 時的選項卡的 PDF 資料
1。
在這種情況下,如何進行以下修改?
修改后的腳本:
function sendReport() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ranges = ss.createTextFinder("1").matchEntireCell(true).findAll();
var showSheets = ranges.reduce((ar, e) => {
if (e.getA1Notation() == "A1") ar.push(e.getSheet().getSheetName());
return ar;
}, []);
var sheets = ss.getSheets();
sheets.forEach(s => {
if (!showSheets.includes(s.getSheetName())) s.hideSheet();
});
SpreadsheetApp.flush();
var pdf = ss.getBlob().setName("sales_report_2021");
var message = {
to: "[email protected]",
subject: "Sales Reports",
body: "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s",
name: "Sales",
attachments: [pdf]
}
MailApp.sendEmail(message);
sheets.forEach(s => s.showSheet());
}
- 在此修改中,
1使用 TextFinder 從所有作業表中檢索到的單元格。1并且,檢索單元格“A1”具有的作業表。并且,單元格“A1”沒有值的作業表1被隱藏。然后,將電子表格轉換為 PDF 資料,并與MailApp.sendEmail. 最后,顯示所有作業表。通過這個流程,你的目標就實作了。
參考:
- 類電子表格的 createTextFinder(findText)
- 隱藏表()
- 顯示表()
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/418057.html
標籤:
