Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
900 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can create an html table, like this:

    function sendEmail(data){

     MailApp.sendEmail({
        to: "[email protected]",
        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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...