Skip to content Skip to sidebar Skip to footer

Send Email From Google Sheet As A Table Without Using Sheets Convertor

Please check the spreadsheet below: spreadsheet https://docs.google.com/spreadsheets/d/1QFPO4bQfYPM4rRJ_6PYxUrYsFgVeUFx89_nZ1mNaLew/edit#gid=0 The script that I'm currently using i

Solution 1:

You can create an html table, like this:

    function sendEmail(data){

     MailApp.sendEmail({
        to: "example@mail.com",
        subject: "Example",
        htmlBody:"<html><body>" + createTable(data)+ "</body></html>"});

    }

    function createTable(data){
        var cells = [];

        var table = "<html><body><br><tableborder=1><tr><th>Start Date</th><th>End Date</th><th>Leave dates</th><th>Status</th></tr>";

        for (var i = 0; i < data.length; i++){
            cells = data[i].toString().split(",");
            table = table + "<tr></tr>";

            for (var u = 0; u < cells.length; u++){
                table = table + "<td>"+ cells[u] +"</td>";
            }
        }

        table=table+"</table></body></html>";
        return table;
    }

Supposing you already have the data in a 2D array (rows and columns values).

Post a Comment for "Send Email From Google Sheet As A Table Without Using Sheets Convertor"