javascript - Table date column formatting with google apps script html service -
i having problems figuring out basic table formatting. hoping can see have , suggest way of changing outcome. google spreadsheet has 2 columns 'number' , 'date'.
my codegs looks
function doget() { return htmlservice .createtemplatefromfile('index') .evaluate(); } function getdata() { return spreadsheetapp .openbyid('1111111111111111111111') .getactivesheet() .getdatarange() .getvalues(); }
my index.html
<? var data = getdata(); ?> <!doctype html> <html> <style> body { font-family: arial; } table { border: 1px solid #ccc; width: 100%; margin:0; padding:0; border-collapse: collapse; border-spacing: 0; } table tr { border: 1px solid #ddd; padding: 5px; } table th, table td { padding: 10px; text-align: left; } table th { text-transform: uppercase; font-size: 14px; letter-spacing: 1px; } </style> <head> </head> <body> <table> <thead> <tr> <th>number</th> <th>date</th> </tr> </thead> <? (var = 1; < data.length; i++) { ?> <tr> <? (var j = 0; j < data[i].length; j++) { ?> <td><?= data[i][j] ?></td> <? } ?> </tr> <? } ?> </table> </body> </html>
when executed date column shows value 'mon dec 05 2016 00:00:00 gmt-0600 (cst)'
in spreadsheet , see '12/5/2016'
i hoping can show me how make work
regards,
chris
this no means elegant solution control date format display use following:
var datestr = 'mon dec 05 2016 00:00:00 gmt-0600 (cst)'; function pad(n){ var pad = ""; if(n < 10){pad = "0" + n}else{pad = n}; return pad; } function shortdate(datestring){ var d = new date(datestring); var curr_date = d.getdate(); var curr_month = d.getmonth() + 1;//zero indexed var curr_year = d.getfullyear(); var shortdate = pad(curr_date) + "/" + pad(curr_month) + "/" + curr_year; return shortdate; } console.log(shortdate(datestr));
this code output uk format date, you'll want switch pad(curr_date) , pad(curr_month).
this mean have write table generating function replace way in table generated need handle date values independently.
Comments
Post a Comment