想要在每次应用条件格式时发送给我的电子邮件

时间:2014-10-22 22:40:40

标签: twitter google-apps-script google-sheets google-apps

我有一个电子表格,可以使用某些Twitter列表中的推文自动更新。我有条件格式应用于工作表,如果其中一条推文中有一个发誓的单词,它会突出显示该特定单元格的红色。

我想要的是在应用条件格式时将单元格(甚至整个电子表格)通过电子邮件发送给我。这可能吗?

此外,有没有办法让电子表格的内容进入"存档"每天都有一张纸,以便主页每天都有新鲜的内容?

感谢您的帮助!

到目前为止,我一直致力于"归档"脚本。我到目前为止的内容如下:

function importData() {

var ss = SpreadsheetApp.getActiveSpreadsheet(); //source ss

var sheet = ss.getSheetByName("Twitter"); //opens the sheet with your source data

var values = sheet.getRange("A:G").getValues(); //gets needed values

var ts = SpreadsheetApp.openById("1g5XaIycy69a3T2YcWhcbBy0hYrxSfoEEz8c4-zP63O8"); //target ss -        paste your key

ts.getSheetByName("Archives").getRange("A:G").setValues(values);}

它表示第11行的范围高度是错误的。

以下是我在使用脏话时尝试使用电子邮件的代码片段。我觉得自己已经处于风口浪尖,但还没到那里。

function onEdit(event)
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = SpreadsheetApp.getActiveSheet();

var cell = ss.getActiveCell();
var range = sheet.getRange(cell.getRow(),1,1,sheet.getDataRange().getLastColumn());
var note = cell.getBackground()

var email = "antadrag@gmail.com";
var subject = "Notice of possible inappropriate tweet";
message = cell.getValue();

if(message.contains ("piss")) {
range.setBackgroundRGB(255, 0, 0);
MailApp.sendEmail(email, subject, message);
}
};

1 个答案:

答案 0 :(得分:1)

要回答您的第一个问题,我同意评论中的Dougs建议。您用来检测脏话的触发器将是调用函数向您发送电子邮件的最佳位置,而不是等待条件格式更改。

关于如何存档数据的查询,您获取范围并将其复制到工作表等等,使您的生活变得有点困难。'copyTo()' operation是您的朋友,因为它会复制整个工作表到另一个电子表格,同时保留条件格式。

以下是一个如何运作的示例:

function importData() {
   var ss = SpreadsheetApp.getActiveSpreadsheet(); //source ss
   var sheet = ss.getSheetByName("Twitter"); //opens the sheet with your source data
   var ts = SpreadsheetApp.openById('SHEET ID');//Opens destination spreadsheet
   sheet.copyTo(ts);//Copy the data to the destination sheet. 
   sheet.clear();//Clear the source sheet.

   //Past this point it's optional, and only if you want to rename the destination sheet. 
   ts.getSheetByName("Copy of Twitter").activate();//Get the destination sheet by name.
   var date = new Date().getDate();//Random variable for the sheets new name
   ts.renameActiveSheet(date);//Set the new sheets name. 
}

这将打开您的源表,将数据复制到您选择的新电子表格中并清除数据源表。或者,我添加了一些行,将目标表重命名为您选择的变量,以便在复制时不易理解(我建议日期或时间,但它可以是任何你真的想要)。