I am getting date columns as general type in excel
I am getting date columns as general type in excel
{
extend: 'excelHtml5',
title: pg_name,
exportOptions: {
columns: ':not(.no-print):visible',
orthogonal: null,
format: {
body: function (data, row, column, node) {
var $node = $(node);
if ($node.find("span.clsColsDateStr").length) {
$node.find("span.clsColsDateStr").remove();
}
var text = $node.text().trim();
var m = moment(text, ['DD-MMM-YYYY'], true);
if (m.isValid()) {
return m.format('YYYY-MM-DD');
}
return text || "";
}
}
},
customize: function (xlsx) {
}
}
Answers
Can you link to a test case showing the issue please? ISO8061 formatted date strings should be dates in Excel after the export.
Allan
Inserting date values into Excel can be tricky. The internal storage format is number of days since
1899-12-30T00:00:00Z.Based on that, my solution looks like this:
I am using Luxon rather than outdated moments.js. But I think, it should be no big deal to convert it.
Many thanks. Interesting to see how you've done it.
For interest, this is how Buttons does it. It only supports YYYY-MM-DD at the moment.
Allan
Looks like there is a problem in version 3. In version this worked fine, now I see in Excel the numeric value, e.g. 40991.541666666664
My custom render function is this:
I suspect the dt export-button exports a string, despite
d.diff(DateTime.fromISO('1899-12-30', { zone: 'utc' }), 'days').daysis a number.In XML data, a numeric column looks like this:
<row r="3"><c t="n" r="A3"><v>62201</v></c>whereas my date field is:
<c t="inlineStr" r="H3" s="68"><is><t xml:space="preserve">40991.541666666664</t></is></c>I would rather expect
<c r="H3" s="68"><v>40991.541666666664</t></c>or something similar.
Any ideas?
Hi,
Can you link to a test case showing the issue so I can look into it in detail please?
Thanks,
Allan
I tried this workaround:
It works in principle, i.e when I open the sheet, then Excel complains about "a problem with some content" and is able to correct it. But certainly not the final solution.
I did not manage it to make it running on https://live.datatables.net but this code should work: