我正在创建一个表单并且换行符不起作用,这使得返回的信息更难以阅读。
我意识到这是在我向Mailapp添加回复之后开始发生的,但找不到解决问题的方法。我也试过\ n和\ r。
有什么建议吗?
function Initialize() {
var triggers = ScriptApp.getProjectTriggers();
for(var i in triggers) {
ScriptApp.deleteTrigger(triggers[i]);
}
ScriptApp.newTrigger("SendGoogleForm")
.forSpreadsheet(SpreadsheetApp.getActiveSpreadsheet())
.onFormSubmit()
.create();
}
function SendGoogleForm(e)
{
try
{
// Personal Info
var timeStamp = e.values[0];
var userName = e.values[1];
var phone = e.values[3];
var preferredContact = e.values[5];
var affliation = e.values[6];
var articleOrBook =e.values[7];
var itemFrom = e.values[8];
var deliverTo = e.values[9];
// Emails
var email = "interlibraryloan@holyfamily.edu";
var userEmail = e.values[4];
//Book Values
var book = e.values[18];
var bookauthor = e.values[19];
var publisher = e.values[20];
var year = e.values[21];
var isbn = e.values[22];
var edition = e.values[23];
//Article Values
var article = e.values[10];
var articleauthor = e.values[11];
var journal = e.values[12];
var volume = e.values[13];
var issue = e.values[14];
var date = e.values[15];
var pages = e.values[16];
// Optional but change the following variable
// to have a custom subject for Google Form email notifications
var subject = "Interlibrary Loan Request Submitted";
var s = SpreadsheetApp.getActiveSheet();
var columns = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "";
var userMessage = "Dear " + userName + ", \n\nThank you for submitting an Intercampus/Interlibrary Loan Request. We will notify you when \n\n" + book + article + " by " + bookauthor + articleauthor + "\n\n is available. \n\nIntercampus or Interlibrary Loan Service \ninterlibraryloan@holyfamily.edu \nHoly Family University \n267-341-3584";
// Only include form fields that are not blank
for ( var keys in columns ) {
var key = columns[keys];
if ( e.namedValues[key] && (e.namedValues[key] != "") ) {
message += key + ' :: '+ e.namedValues[key] + "\n\n";
}
}
// This is the MailApp service of Google Apps Script
// that sends the email. You can also use GmailApp for HTML Mail.
MailApp.sendEmail(email, userEmail, subject, message);
MailApp.sendEmail(userEmail, email, subject, userMessage);
} catch (e) {
Logger.log(e.toString());
}
}
答案 0 :(得分:0)
这个character not being preserved似乎存在一些问题,但逃避似乎至少在中途fixed。
如果这是进入公式栏,您想使用"Hello"&CHAR(10)&"world!"
作为换行符。
否则你可以改为use paragraphs:
var body = DocumentApp.getActiveDocument().getBody();
// Append a document header paragraph.
var header = body.appendParagraph("A Document");
header.setHeading(DocumentApp.ParagraphHeading.HEADING1);
// Append a section header paragraph.
var section = body.appendParagraph("Section 1");
section.setHeading(DocumentApp.ParagraphHeading.HEADING2);
// Append a regular paragraph.
body.appendParagraph("This is a typical paragraph.");
这在以HTML格式查看输出时特别有用,因为浏览器会消除额外的空白区域,但段落可以很好地理解您想要的功能。