我制作了一个小脚本,通过电子表格中的电子邮件发送文本。 我使用.getValue()得到了单元格的文本,但是当我的单元格有两行或更多行(Ctrl + enter)时,它只是将它们放在我在电子邮件中发送的表格中的同一行。
我想知道是否有一种方法可以在使用.getValue()提取GoogheSheet格式时保留GoogheSheet格式,或者如果我需要重新处理字符串,如果是这样,我如何让任何RE检测新行...?
以下是我用于提取细胞的编码:
INSERT INTO [ChildModel]
([Resource] ,[Role] ,[Category], [ParentId])
VALUES
('Foo', 'Bar', 'Baz', 1),
('Foo', 'Bar', 'Bof', 1);
答案 0 :(得分:0)
所以Mail发送带有文本的重建表,所有这些都是在html Mail中插入的:
function weeklyReport() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var rowMonth = [31,28,31,30,31,30,31,30,31,30,31,30];
var today = new Date();
var todayYear = today.getYear();
var todayMonth = today.getMonth();
var todayDate = today.getDate();
// Calc the number of rows depending of months that have passed
var rowCell=0;
var i = 0;
do {
rowCell+=rowMonth[i];
i++;
} while (i < todayMonth);
rowCell+=3 + todayDate
var range1 = readInListD(rowCell-4, 1);
var range2 = readInList(rowCell-4, 4);
var subject = 'Weekly report Clem Michard';
var greetings = 'Hi, ';
var sentence = 'please find my weekly report below:';
var table = textToTable(range1, range2);
var signature = 'Clem';
var tables = today;
var cmEmail= '***';
var owaEmail = '***';
var headEmail = '***';
var htmlBodyA =
"<html>"+
"<head>"+
"<style>"+
"table, th, td {"+
"border: 1px solid black;"+
"border-collapse: collapse;"+
"}"+
"</style>" +
"</head>"+
"<body>"+
"<p>" + greetings + "</p>"+
"<p>" + sentence + "</p>"+
"<pre>" + table + "</pre>"+
"<p>" + signature + "</p>"+
"</body>"+
"</html>";
/*- Message envoyé aux particpants avec un e-mail valide -*/
MailApp.sendEmail({
to: headEmail,
bcc: cmEmail,
subject: subject,
name: "Clément Michard",
replyTo: cmEmail,
htmlBody: htmlBodyA})
}
并使用它来撰写表格:
function textToTable(col1, col2){
/*
This method converts a list of str into an HTML table
takes 2 lists to build a table.
*/
var listC1, listC2, text, lLen, i, j;
listC1 = col1;
listC2 = col2;
lLen = listC1.length;
text = "<table><tr><th>" + "Date" + "</th><th>" + "Report" + "</th></tr>";
for (i = 0; i < lLen; i++){
text += "<tr><td>" + listC1[i] + "</td><td>" + listC2[i] + "</td></tr>";
}
text += "</table>";
return(text);
}