8000 Exporting Date-Times in Iso Format · Issue #640 · SheetJS/sheetjs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Exporting Date-Times in Iso Format  #640
Closed
@SCullman

Description

@SCullman

I want to export date/time values to JSON formatted as ISO 8601 values

My current script:

const XLSX = require('xlsx');
...
const file = XLSX.readFile(path,{cellDates:true, cellNF:false});
for (sheet in file.Sheets){
     //remove prerendered values, otherwise dateNF is ignored
     for (cellref in sheet){
         const c = sheet[cellref];
         if(c.t==="d"){
             delete c.w;
             delete c.z; 
         }
    }
   const format = "YYYY-MM-DD hh:mm:ss";
   //const format = "YYYY-MM-DDThh:mm:ss"; throws exception as it doesn't recognize T
   const data = XLSX.utils.sheet_to_json(sheet, {header: 1, dateNF:format});
   .....
}

The cells itself already contain the correct datetime inside the v(alue) attribute.

I suggest an option like
XLSX.utils.sheet_to_json(sheet, {header: 1, ExportDatesAsISO:true});

Test data:
datum.xlsx

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0