问题
I am sending email from google sheet data via google apps script. But the problem is the spacing is not correctly formatted
I have tried using " " but the spacing remains the same. How to make spacing in email body?
for (var m=0;m<resultArr.length;m++) {
body+= "For Part No "+resultArr[m][0].toString()+" " +" Month "
+resultArr[m][1].toString()+",Quantity is "+resultArr[m][2].toString()+"
<br>";
}
I want to move the "Month" and "Quantity" to the right so that it will align correctly in email body
回答1:
By default, html spaces are collapsed. You can set white-space to pre
or pre-wrap
to preserve spaces.
var body = "<body style='white-space:pre-wrap'>";
for (var m=0;m<resultArr.length;m++) {
body+= "For Part No "+resultArr[m][0].toString()+" " +" Month "+resultArr[m][1].toString()+",Quantity is "+resultArr[m][2].toString()+" <br>";
}
body += "</body>"
回答2:
Try this loop:
for (var m=0;m<resultArr.length;m++) {
body+= "<td style='font-family:Arial; font-size:15px;'>For Part No "+resultArr[m][0].toString()+" " +"</td><td> Month " +resultArr[m][1].toString()+"</td><td>Quantity is "+resultArr[m][2].toString()+"</td>";
}
add this table around the loop
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<!-- loop goes here -->
</tr>
</tbody>
</table>
The loop will create 3 columns while the rest of the code will create the code necessary for a table to hold.
来源:https://stackoverflow.com/questions/56746063/how-to-use-html-spacing-in-email-body-google-apps-script