简体   繁体   中英

Data does not display as in google sheets format

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

How about the following modification?

From :

var data = sheet.getDataRange().getValues();

To :

var data = sheet.getDataRange().getDisplayValues();

Reference :

If this was not useful for you, please tell me. I would like to modify.

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