简体   繁体   中英

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 is working fine thanks to the posts I've seen here. I just wanted to send it in a better way. I've already checked other posts and I even saw the SheetConverter but is too complicated for me.

Current Result: https://drive.google.com/file/d/1-OQqnsRwIJaoXOnYZEtPxHy6r3buB8H7/view?usp=sharing

Please check image for the desired result. Thanks! https://drive.google.com/file/d/1p7cJBTyaZ1ZqI5Jv5WWOGg6_Q-JegfHj/view?usp=sharing

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><table border=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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM