How to align email body in google apps script?

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 answer

  • answered 2019-06-25 05:52 Tanaike

    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.


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