您好我正在尝试提取我的电子邮件的PlainBody内容,并且正在完成提取我的电子邮件,直到某些时候我遇到一个错误,说您的输入包含的单个单元格中的最多50000个字符。
如何设置我在Google App脚本中提取的字符数限制以避免此错误。?
function getEmailsRange() {
//Change sheet3 to sheet you would like the data to be pasted
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Raw");
sheet.getRange('A1:D15000').clearContent();
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
//maximum emails to be extracted 500
//is:unread in:MANILA
var threads = GmailApp.search("after:2017/5/5 before:2017/5/6 in:REPORT",0,500);
var menuEntries = [ {name: "Load Emails", functionName: "getEmails"} ];
spreadsheet.addMenu("Email Extract", menuEntries);
var row = 1;
for (var i = 0; i < 50000; i++) {
var messages=threads[i].getMessages();
for (var m=0; m < messages.length; m++) {
sheet.getRange(row,4).setValue(messages[m].getDate());
sheet.getRange(row,2).setValue(messages[m].getPlainBody());
sheet.getRange(row,1).setValue(messages[m].getSubject());
sheet.getRange(row,3).setValue(messages[m].getFrom());
row++;
}
}
}
//var ss = SpreadsheetApp.getActiveSpreadsheet();
function Deleterow() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('Processed'); // change to your own
var values = s.getDataRange().getValues();
for (var row in values)
if (values[row][5] == 'DELETE')
s.deleteRow(parseInt(row)+1);
};
答案 0 :(得分:3)
问题是因为您要将电子邮件正文设置为电子表格中的单元格,而单元格的字符数不能超过50000个。
您可以更改以下行:
sheet.getRange(row,2).setValue(messages[m].getPlainBody());
到
sheet.getRange(row,2).setValue(messages[m].getPlainBody().substring(0, 50000));
这将仅将前50000个字符添加到单元格中。其他选项是将电子邮件提取到多个单元格或将电子邮件提取到Google文档中。