Reputation: 299
I am using google apps script to fetch filtered and sorted data from spreadsheet and then display the same on html page. However, I get badly formatted data and not as one displayed in the sheet.
My code
function gettssubmitted() {
var employee = getcurruser();
var doc = SpreadsheetApp.openById(timesheet);
var sheet = doc.getSheetByName("Current");
var data = sheet.getDataRange().getValues();
var retdata = ArrayLib.filterByText(data, 1, employee);
retdata = ArrayLib.sort(retdata, 2, Desc);
Logger.log("timesheet");
Logger.log(data);
return retdata;
}
And on the html side
<body>
<? var logged_user = getcurruser(); ?>
<label><?=logged_user?></label>
<? var data = gettssubmitted(); ?>
<table>
<tr>
<th>Time Sheet Date</th>
<th>Job Ticket</th>
<th>Start Time</th>
<th>End Time</th>
<th>Comments</th>
</tr>
<? for (var i = 0; i < data.length; i++) { ?>
<tr>
<td class="dispdate"><?= data[i][2].toString("d MMMM yyyy") ?></td>
<td><?= data[i][3] ?></td>
<td><?= data[i][4] ?></td>
<td><?= data[i][5] ?></td>
<td><?= data[i][6] ?></td>
</tr>
<? } ?>
</table>
</body>
however when I try to display the following data in the sheet
Timestamp Employee TimeSheet Date Job Ticket Slot Start Slot End Comments Employee Mail Supervisor Mail Status January 1, 2018-5:00:44 AM GST XXXY 12/28/17 67135 8:00 11:00 Complain adkljf aslkdf Submit January 1, 2018-5:00:44 AM GST XXXY 12/28/17 67136 11:00 17:00 kidding askdf adkjlf Submit
It is shown as
Time Sheet Date Job Ticket Start Time End Time Comments Tue Jan 02 2018 00:00:00 GMT+0400 (GST) 67135 Sat Dec 30 1899 08:18:48 GMT+0400 (GST) Sat Dec 30 1899 12:18:48 GMT+0400 (GST) Description Tue Jan 02 2018 00:00:00 GMT+0400 (GST) 67136 Sat Dec 30 1899 13:18:48 GMT+0400 (GST) Sat Dec 30 1899 17:18:48 GMT+0400 (GST) Description
How do I get it to display in the same format as in sheet.
Cheers
Upvotes: 0
Views: 62
Reputation: 201378
How about the following modification?
var data = sheet.getDataRange().getValues();
var data = sheet.getDataRange().getDisplayValues();
If this was not useful for you, please tell me. I would like to modify.
Upvotes: 1