我有点格式化问题。我使用此程序来跟踪我的采购订单,并且已将其设置为向我发送每天下达的所有采购订单,并且电子邮件如下所示:
然后我用以下代码设置了一个Google工作表,将电子邮件拉入工作表:
var SEARCH_QUERY = "label:inbox is:unread from:[SERVER EMAIL]";
function getEmails_(q) {
var emails = [];
var threads = GmailApp.search(q);
for (var i in threads) {
var msgs = threads[i].getMessages();
for (var j in msgs) {
emails.push([msgs[j].getBody().replace(/<.*?>/g, '\n')
.replace(/^\s*\n/gm, '').replace(/^\s*/gm, '').replace(/\s*\n/gm, '\n')
]);
}
}
return emails;
}
function appendData_(sheet, array2d) {
sheet.getRange(sheet.getLastRow() + 1, 1, array2d.length, array2d[0].length).setValues(array2d);
}
function saveEmails() {
var array2d = getEmails_(SEARCH_QUERY);
if (array2d) {
appendData_(SpreadsheetApp.getActiveSheet(), array2d);
}
}
这非常适合导入数据,但不幸的是,所有数据都导入了A2单元,如下所示:
是否有一种方法可以使其更像电子邮件中的网格格式?当我将其放入松弛状态时,它没有格式化功能,因为它全部位于一个单元中。这是我用来将其推送到Slack的代码:
function triggerSlackRequestProgress(channel, msg) {
var slackWebhook = "[SLACK WEBHOOK]";
var payload = { "channel": channel, "text": msg, "link_names": 1, "username": "Email Test", "icon_emoji": ":cowboykeen:" };
var options = { "method": "post", "contentType": "application/json", "muteHttpExceptions": true, "payload": JSON.stringify(payload) };
Logger.log(UrlFetchApp.fetch(slackWebhook, options));
}
function notifySlackChannelOfProgress() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
if (!sheet.getRange("A2").getValue()) return;
var channel = getChannel();
var msg = createProgressMessage(sheet);
triggerSlackRequestProgress(channel, msg);
}
function isTest() {
return false;
}
function getChannel() {
if(isTest()) {
return "[SLACK CHANNEL]";
} else {
return "[SLACK CHANNEL]";
}
}
它看起来像这样:
但是我更希望能够对其进行更多编辑以使其看起来像这样。订单日期,请求者,描述等都在单独的单元格中,因此我可以对其进行格式化:
对他的任何帮助将不胜感激!