DateTime detection /formatting problem #59

Closed
opened 2014-05-08 15:12:34 +00:00 by vratiu · 7 comments
vratiu commented 2014-05-08 15:12:34 +00:00 (Migrated from github.com)

I'm trying to convert this file: https://www.dropbox.com/s/qbjhjhfjx02dyfa/ATtest.xlsx
to csv and my output is: https://www.dropbox.com/s/tf5e2j6mag74c1y/ATtest.csv
and was expectig: https://www.dropbox.com/s/qt24pq1qiie2bto/file.csv

>j.readFile("/tmp/ATtest.xlsx")[1].Sheets; 
{ Sheet1: 
   { '!ref': 'A1:A65536',
     A1: 
      { v: 'Timestamp',
        t: 's',
        r: '<t>Timestamp</t>',
        h: 'Timestamp',
        w: 'Timestamp' },
     A2: 
      { v: 41609.0355555556,
        t: 'n',
        w: '51:12.0' },
     A3: 
      { v: 41609.0367361111,
        t: 'n',
        w: '52:54.0' },
     A4: 
      { v: 41609.0506365741,
        t: 'n',
        w: '12:55.0' },
     A5: 
      { v: 41609.1358333333,
        t: 'n',
        w: '15:36.0' },
     A6: 
      { v: 41609.1373148148,
        t: 'n',
        w: '17:44.0' },
     A7: 
      { v: 41609.1595949074,
        t: 'n',
        w: '49:49.0' } } }

Library version

> j.version
'XLS 0.6.17 ; XLSX 0.6.2'

Open Office also truncates the output showing 49:49.0 instead of 12/01/2013 03:49:49 but will show the right value in the input line

I'm trying to convert this file: https://www.dropbox.com/s/qbjhjhfjx02dyfa/ATtest.xlsx to csv and my output is: https://www.dropbox.com/s/tf5e2j6mag74c1y/ATtest.csv and was expectig: https://www.dropbox.com/s/qt24pq1qiie2bto/file.csv ``` >j.readFile("/tmp/ATtest.xlsx")[1].Sheets; { Sheet1: { '!ref': 'A1:A65536', A1: { v: 'Timestamp', t: 's', r: '<t>Timestamp</t>', h: 'Timestamp', w: 'Timestamp' }, A2: { v: 41609.0355555556, t: 'n', w: '51:12.0' }, A3: { v: 41609.0367361111, t: 'n', w: '52:54.0' }, A4: { v: 41609.0506365741, t: 'n', w: '12:55.0' }, A5: { v: 41609.1358333333, t: 'n', w: '15:36.0' }, A6: { v: 41609.1373148148, t: 'n', w: '17:44.0' }, A7: { v: 41609.1595949074, t: 'n', w: '49:49.0' } } } ``` Library version ``` > j.version 'XLS 0.6.17 ; XLSX 0.6.2' ``` Open Office also truncates the output showing 49:49.0 instead of 12/01/2013 03:49:49 but will show the right value in the input line
SheetJSDev commented 2014-05-08 15:37:42 +00:00 (Migrated from github.com)

For whatever reason I can't download the original file. Is the link correct?

Also, Can you show the output from

j.readFile("/tmp/ATtest.xlsx", {cellNF:true})[1].Sheets; 

That should display the number formats.

For whatever reason I can't download the original file. Is the link correct? Also, Can you show the output from ``` j.readFile("/tmp/ATtest.xlsx", {cellNF:true})[1].Sheets; ``` That should display the number formats.
SheetJSDev commented 2014-05-08 15:52:48 +00:00 (Migrated from github.com)

@vratiu The dropbox issue only occurs on phone (strangely enough). It downloaded on my computer.

Did you look at the output from Excel itself? This is what I see:

Excel 2013:

Excel 2011:

Using the j command line tool:

@vratiu The dropbox issue only occurs on phone (strangely enough). It downloaded on my computer. Did you look at the output from Excel itself? This is what I see: Excel 2013: ![](http://i.imgur.com/0Ka85Xe.png) Excel 2011: ![](http://i.imgur.com/mOoKAmp.png) Using the `j` command line tool: ![](http://i.imgur.com/mnRK5pZ.png)
SheetJSDev commented 2014-05-08 15:59:25 +00:00 (Migrated from github.com)

Both Excel 2011 and Excel 2013 agree on the format:

As a result, I'm inclined to say this is not a bug.

Both Excel 2011 and Excel 2013 agree on the format: ![](http://i.imgur.com/2ZBzx7X.png) ![](http://i.imgur.com/wpiBKxk.png) As a result, I'm inclined to say this is not a bug.
vratiu commented 2014-05-08 15:59:39 +00:00 (Migrated from github.com)

@SheetJSDev I've looked with Open Office and yes it shows up truncated exactly like your screenshots.
But, if you look closer in the input line near the "fx" you can notice the full date-time value.
Converting these files to csv will output the correct timestamp.
Also, I've tried other converters in two different languages, just to see how they behave, and they output the date-time correctly.

@SheetJSDev I've looked with Open Office and yes it shows up truncated exactly like your screenshots. But, if you look closer in the input line near the "fx" you can notice the full date-time value. Converting these files to csv will output the correct timestamp. Also, I've tried other converters in two different languages, just to see how they behave, and they output the date-time correctly.
SheetJSDev commented 2014-05-08 16:04:51 +00:00 (Migrated from github.com)

@vratiu the content in the top bar will show the same format (mm/dd/yyyy HH:MM:SS) regardless of the number format in the cell (so long as excel thinks it is a date)

If you want to see that, download http://oss.sheetjs.com/test_files/number_format.xlsm and look at cells B12:B20 -- all of them show the same content 10/18/1933 16:17:37 in the top bar but show different texts in the cell.

If you want to recover the original date as a JS date, there is a roundabout way (I'll make a few changes soon to simplify this):

> var x=require('ssf').parse_date_code(41609.0355555556) /* This number is the .v from the cell */
> x
{ D: 41609,
  T: 3072,
  u: 0.000003978610038757324,
  y: 2013,
  m: 12,
  d: 1,
  H: 0,
  M: 51,
  S: 12,
  q: 0 }
> new Date(x.y,x.m,x.d,x.H,x.M,x.S)
Wed Jan 01 2014 00:51:12 GMT-0800 (PST)
@vratiu the content in the top bar will show the same format (mm/dd/yyyy HH:MM:SS) regardless of the number format in the cell (so long as excel thinks it is a date) If you want to see that, download http://oss.sheetjs.com/test_files/number_format.xlsm and look at cells B12:B20 -- all of them show the same content `10/18/1933 16:17:37` in the top bar but show different texts in the cell. If you want to recover the original date as a JS date, there is a roundabout way (I'll make a few changes soon to simplify this): ``` > var x=require('ssf').parse_date_code(41609.0355555556) /* This number is the .v from the cell */ > x { D: 41609, T: 3072, u: 0.000003978610038757324, y: 2013, m: 12, d: 1, H: 0, M: 51, S: 12, q: 0 } > new Date(x.y,x.m,x.d,x.H,x.M,x.S) Wed Jan 01 2014 00:51:12 GMT-0800 (PST) ```
vratiu commented 2014-05-08 16:22:50 +00:00 (Migrated from github.com)

@SheetJSDev
Where in the code could I check the format and do the conversion to have this case enabled ?
Maybe here ?

xlsx.js 11780:
p.w = SSF.format(fmtid,p.v,_ssfopts);
@SheetJSDev Where in the code could I check the format and do the conversion to have this case enabled ? Maybe here ? ``` xlsx.js 11780: p.w = SSF.format(fmtid,p.v,_ssfopts); ```
SheetJSDev commented 2014-05-08 16:52:50 +00:00 (Migrated from github.com)

@vratiu ssf is a separate module (http://npm.im/ssf), but you can get at it with j.XLS.SSF

If you want to reproduce the text that excel uses, try format mm/dd/yyyy HH:MM:SS :

> var v = require('j').readFile("ATtest.xlsx")[1].Sheets.Sheet1.A2.v
> require('ssf').format("mm/dd/yyyy  HH:MM:SS",v)
'12/01/2013  00:51:12'
@vratiu ssf is a separate module (http://npm.im/ssf), but you can get at it with `j.XLS.SSF` If you want to reproduce the text that excel uses, try format `mm/dd/yyyy HH:MM:SS` : ``` > var v = require('j').readFile("ATtest.xlsx")[1].Sheets.Sheet1.A2.v > require('ssf').format("mm/dd/yyyy HH:MM:SS",v) '12/01/2013 00:51:12' ```
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#59
No description provided.