Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=HTML+table+function+-+1222738219
widthauto

Excerpt
namea

A group of functions designed to take an array of text and convert it to an HTML table.

...

Code Block
function wrapTag(string text, string tag) {
    return "<" + tag + ">" + text + "</" + tag + ">";
}

function tableHead(string [] headings){
    string body;
    for(string hd in headings)
    {
        body += wrapTag(hd, "th");
    }
    return wrapTag(body, "tr");   
}

function htmlTable(string [] headings, string [] data){
    
    string body = tableHead(headings);
    string temp;
    int colCount = size(headings);
    
    for(int x = 0; x < size(data); x ++) {
        temp += wrapTag(data[x], "td");
        
        if(x > 0) {
            if((x+1) % (colCount) == 0) {
                body += wrapTag(temp, "tr");
                temp = "";
            }
        }
    }
    return wrapTag(body, "table");
}

string [] headings = "Column A|Column B|Column C";
string [] data = "1A|1B|1C|2A|2B|2C|3A|3B|3C";

runnerLog(htmlTable(headings, data), true); //see formatted output
return htmlTable(headings, data); //see raw output

Output:

...

We've encountered an issue exporting this macro. Please try exporting this page again later.