簡體   English   中英

使用 Google Apps 腳本將報表從工作表導入 Email

[英]Import Report from Sheet to Email using Google Apps Script

我在谷歌表中有定期填充數據的報告。 我想使用 google 應用程序腳本將此 Google 表格報告發送到特定的 email 地址。 我嘗試了不同的方法將該報告捕獲到 email 正文中,以便接收者可以在 email 中接收他的報告,但找不到任何解決方案以 email 正文的形式發送它。 這是我的報告表的鏈接:

https://docs.google.com/spreadsheets/d/11g_a4lgcpBftBxd52nVpGGnlmC78bWeUOg7xk5GejWw/edit?usp=sharing

我有以下代碼,它從工作表中提取任何圖表並將它們導入郵件。 但我希望將整個工作表導出到郵件中,而不僅僅是圖表。 任何幫助,將不勝感激。

function email(sheet,toMail,msg){

var charts = sheet.getCharts();

var slides= SlidesApp.create("sample")
var slide = slides.getSlides()[0]

var emailImages={};
var chartBlobs= new Array(charts.length)
var emailBody="";

for (var i=0;i<charts.length;i++)
  {
   var image=slide.insertSheetsChartAsImage(charts[i]);
   chartBlobs[i]= image.getAs("image/png").setName("chartBlob"+i);
   emailBody =emailBody + "<p align='left'><imag src='cid:chart" +i+"'></p>
   emailImages["chart"+i]=chartBlobs[i];
  }

   MailApp.sendEmail({
             to:toMail,
             subject:"ABC",
             htmlBody:emailBody,
             inlineImages:emailImages});


             DriveApp.getFileById(slides.getId()).setTrashed(true);
}

制作 文件:get請求將返回以下 exportLinks

對於 Google 文檔文件:

{
 "exportLinks": {
  "application/rtf": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=rtf",
  "application/vnd.oasis.opendocument.text": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=odt",
  "text/html": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=html",
  "application/pdf": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=pdf",
  "application/epub+zip": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=epub",
  "application/zip": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=zip",
  "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=docx",
  "text/plain": "https://docs.google.com/feeds/download/documents/export/Export?id=1qvfrIFTYZ3lL0pkP6VTEG_YdThY0UeB-Oyjfl48sL5o&exportFormat=txt"
 }
}

對於 Google 表格文件:

{
 "exportLinks": {
  "application/x-vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=ods",
  "text/tab-separated-values": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=tsv",
  "application/pdf": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=pdf",
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=xlsx",
  "text/csv": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=csv",
  "application/zip": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=zip",
  "application/vnd.oasis.opendocument.spreadsheet": "https://docs.google.com/spreadsheets/export?id=1wGIfU1L9__Tt1JIxfkCYqUiUH1RSIt3P7KsMsuVUYIc&exportFormat=ods"
 }
}

換句話說:沒有將 Google 表格文件導出到 HTML 的內置功能

這就是為什么您可以 email 從 UI 中將 Docs 文件作為 HTML 而不是 Google 表格的原因。

結論:

您需要自己構建一個 html 表,以將工作表內容放入您的 email 正文中。

是一個如何做到這一點的示例。

或者 - 考慮將整個工作表內容轉換為圖像,因為圖像可以插入到 email 主體中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM