I was using below api to generate the excel from js object.
var ws2 = XLSX.utils.json_to_sheet(dataForSheet, {skipHeader: true});
The json object have date column and date-time column . But in the exported excel, the datetime column can not bee seen unless you double-click it.
How can this issue be solved?
I tried the dateNF property like below, but does not work, it will affect the date column as well.
var ws2 = XLSX.utils.json_to_sheet(dataForSheet, {skipHeader: true,dateNF: 'YYYYMMDD HH:mm:ss'});
I also post this question in SO.
https://stackoverflow.com/questions/49483419/how-to-make-the-datetime-column-shown-correctly-on-the-ms-excel
You have to manually set the column width to 17 characters (the format yyyymmdd hh:mm:ss generates 17-character values):
if(!ws['!cols']) ws['!cols'] = [];
ws['!cols'][/* column index for date */] = { wch: 17 };
https://jsfiddle.net/sheetjs/9xneL9wh/ is a sample fiddle:
var ws = XLSX.utils.json_to_sheet([[new Date()]], {skipHeader:true, dateNF: 'YYYYMMDD HH:mm:ss'});
if(!ws['!cols']) ws['!cols'] = [];
ws['!cols'][0] = { wch: 17 };
var wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "issue1052");
XLSX.writeFile(wb, "issue1052.xlsx");
Most helpful comment
You have to manually set the column width to 17 characters (the format
yyyymmdd hh:mm:ssgenerates 17-character values):https://jsfiddle.net/sheetjs/9xneL9wh/ is a sample fiddle: