How to align email body in google apps script?

本小妞迷上赌 提交于 2019-12-11 05:56:22

问题


I'm facing issue in aligning the data from google sheets when sending it in email body.

So far, its spacing out according to the part numbers. I want "months" and "quantity" in a straight column.

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>"

I expect the month and column in one straight line


回答1:


In your case, for example, how about using table? Please think of this as just one of several answers.

Modified script:

body += "<table style=\"border-collapse: separate; border-spacing: 20px 0px;\">"
for (var m=0;m<resultArr.length;m++) {
  body+= "<tr><td>For Part No  "+resultArr[m][0].toString()+ "</td><td align=\"right\">Month "+resultArr[m][1].toString()+"</td><td align=\"right\">Quantity is "+resultArr[m][2].toString()+"</td></tr>";
}
body += "</table>";
  • In this modified script, the table is created without the borders and with the margin between columns of 20 px.

References:

  • border-collapse
  • border-spacing

If I misunderstood your question and this was not the direction you want, I apologize.



来源:https://stackoverflow.com/questions/56747354/how-to-align-email-body-in-google-apps-script

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