How to use HTML spacing in email body Google Apps Script?

我只是一个虾纸丫 提交于 2019-12-13 03:09:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!