17

Does someone have an idea how the cell object should look like when you want to transform a value in milliseconds to a duration format of h:mm?

At the moment I have a cell object which looks like { t: 'n', v: value, z: 'h:mm' } but it doesn't display the correct hour and minutes.

Logan_Dupont
  • 355
  • 3
  • 13

2 Answers2

0

The z attribute is deprecated. Try this: { t: 'n', v: value, s: { numFmt: 'h:mm' } }

Daniele Ricci
  • 15,422
  • 1
  • 27
  • 55
  • 1
    Where did you see that `z` attribute is deprecated? I am not able to find it in the [changelog](https://github.com/SheetJS/sheetjs/blob/master/CHANGELOG.md). It even seems that `s` is a pro feature. – Logan_Dupont Jun 11 '20 at 09:11
0

const unixEpochMilliseconds = moment().valueOf();

const ws = XLSX.utils.aoa_to_sheet([
  ["a", "string"],
  [1, "number"],
  [{
    t: "d",
    v: moment(unixEpochMilliseconds).toDate(),
    z: "h:mm"
  }, "time"]
]);

const table = XLSX.utils.sheet_to_html(ws);
document.body.innerHTML = table;
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.26.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.2/xlsx.js"></script>
ardean
  • 152
  • 7