A way to specify date formating when using XLSX.utils.sheet_to_row_object_array()

Note: these changes are in the repo and will appear in version 0.9.5.
If you read in with cellDates:true, the date-stored-as-number cells will be proper dates.
If you set the dateNF key of the options object to a number format string, the formatter will use it. Following the example from my previous comment:
> var wb = XLSX.readFile('write.xlsx', {cellDates:true});
> wb.Sheets.SheetJS.C3
{ t: 'd', v: 2014-02-19T14:30:00.000Z, w: '2/19/14' } // <-- note: v is a date object
> delete wb.Sheets.SheetJS.C3.w
true
> XLSX.utils.format_cell(wb.Sheets.SheetJS.C3);
'2/19/14' <-- defaults to the number format code 14
> delete wb.Sheets.SheetJS.C3.w
true
> XLSX.utils.format_cell(wb.Sheets.SheetJS.C3, null, {dateNF:"YYYY-MM-DD"});
'2014-02-19' <-- uses the override
ref: https://github.com/SheetJS/sheetjs/issues/134

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

J2EE คืออะไร

วิธีแก้ : แก้ไขตารางแล้ว save ไม่ได้ ต้องสร้างใหม่ - Saving changes is not permitted in SQL Server Management Studio

การออกแบบ RESTful API - วิธีปฏิบัติที่ดี