[英]How do I use sheets.AppendRow? I keep receiving an error [Ljava.lang.Object;@29080d11 in all the cells
I am retrieving the body of a email and inserting into google sheets.我正在检索电子邮件的正文并插入到 Google 表格中。 Keep getting [Ljava.lang.Object;@29080d11 errors.
不断收到 [Ljava.lang.Object;@29080d11 错误。 I already have retrieveing the data working well.
我已经检索了运行良好的数据。 I have a little problem with building the array to append to google sheets.
我在构建数组以附加到谷歌表格时遇到了一些问题。 This is my code;
这是我的代码;
function processInboxToSheet() {
// var label = GmailApp.getUserLabelByName("NEWNOPS");
var label = 'Inbox';
var threads = GmailApp.search('subject:"New Quality Test Results"');
// var threads = label.getThreads();
// Set destination sheet
var sheet = SpreadsheetApp.getActiveSheet();
// Get all emails with subject
for (var i = 0; i < threads.length; i++) {
var tmp;
message = threads[i].getMessages()[0]; // second message in thread
content = message.getPlainBody(); // remove html markup
// next three lines cleans the message to just the data
content = content.substr(content.search("Tank 1")); // remove beginning of trash
var n = content.lastIndexOf("INH");
content = content.substr(0,(n+14)); // get the body of the wanted data
//Logger.log(n);
content = content.split("\n"); // create array based on newline
var data = [];
data.push(content[0].match(/[0-9]{2}[\/][0-9]{2}[\/][0-9]{4}/)); //Date
data.push(content[1].match("")); //Blank /\d*\.\d{2}/
data.push(content[2].match(/\d*\.?\d{2}/)); //Bfat
data.push(content[3].match(/\d*\.\d{2}/)); //Prot
data.push(content[4].match(/\d*\.\d{2}/)); //Lact
data.push(content[5].match(/\d*\.\d{2}/)); //OS
data.push(content[6].match(/\d*,\d{3}/)); //SPC
data.push(content[7].match(/\d*\,\d{3}/)); //SCC
data.push(content[8].match(/\d{2}/)); //MUN
data.push(content[9].match(/-\d.\d{4}/)); //FRZ
data.push(content[10].match(/\d{2}/)); //TMP
data.push(content[11].match(/\d/)); //INH
Logger.log(data);
if (content) {
sheet.appendRow(data);
// if no match); display error
} // End if
} // End for loop
};
my data;我的数据;
Producer 32698-1 Date Of Notice 02/04/2020
Cow Milker3
8831 CHAPEL RD
EASTERN, MD 21664
Tank 1 Sample Date 02/03/2020 B O
Bfat 4.09
Prot 3.11
Lact 4.720
OS 5.64
SPC 1,000
SCC 100,000
MUN 12
FRZ -0.5420
TMP 37
INH 0
The problem is that match
returns an Array
or null
, so data
is an "Array of Arrays" (multidimensional Array) but appendRow
requires a "simple" Array.问题是
match
返回一个Array
或null
,所以data
是一个“数组数组”(多维数组),但appendRow
需要一个“简单”数组。
Unfortunately there isn't a "simple fix" (like adding one code line or few characters).不幸的是,没有“简单的修复”(例如添加一行代码或几个字符)。 You should rethink the logic of your script to handle the case that there match returns
null
because it's not a valid value to be passed to Google Sheets.您应该重新考虑脚本的逻辑来处理匹配返回
null
的情况,因为它不是传递给 Google 表格的有效值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.