question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrongly parsing csv string cell as date

See original GitHub issue

When reading a CSV string, some fields that should be parsed as strings are parsed as dates.

This happens when the string ends with something that resembles a date.

Use the following snippet to reproduce.

var foo = 'foo,bar\nfoo2,bar2\n"Wololo thing - ends Feb. 15, 2017","Wololo thing - ends Feb. 15, 2017 bar"';
var w = XLSX.read(foo, {type: "string", cellDates: true});
console.log(w.Sheets.Sheet1);

Expected result: the third row contains 2 strings:

{t: "s", v: "Wololo thing - ends Feb. 15, 2017"}
{t: "s", v: "Wololo thing - ends Feb. 15, 2017 bar"}

Actual result: the third row contains

{t: "d", v: Wed Feb 15 2017 00:00:00 GMT-0200 (-02), w: "2/15/17"}
{t: "s", v: "Wololo thing - ends Feb. 15, 2017 bar"}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:8
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

21reactions
speedofsound99commented, May 22, 2018

I’m using xlsx.read(foo, { type: ‘string’, raw:true }); and I’m getting the dates in the expected plain text format

13reactions
mcdadocommented, Feb 14, 2018

For example, the string Today is Jan 25 2018 can be reproduced by setting a cell to 43125 with format "Today is "mmm dd yyyy. Should the string be considered a date or a string?

This seems crazy to me! Keep it as a string of course!!!

This behavior should be disabled on request. I’m importing a CSV (tried with xls too) to perform corrections and it keeps on converting values like “VIA MARTUCCI 2” to the date “3/2/01”, I tried using raw: true but it simply uses the number “36952”. Only with xlsx files it doesn’t convert these values.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stop Excel from automatically converting certain text values to ...
Open the CSV file as text (notepad); Copy it (ctrl+a, ctrl+c). Paste it in a new excel sheet -it will all paste in...
Read more >
Formatting Dates for CSV Imports - Administration - Echo360
Basic steps: select the date column, right-click and select Format Cells, then select Custom and enter yyyy-mm-dd in the text field. Open the...
Read more >
Make my Excel parse dates from CSV like everyone else's
What I have discovered: The Excel documentation is misleading, if not wrong. The date format of the cell apparently only serves for display....
Read more >
Stop Excel from Converting Text to Number or Date format ...
Option 1: Rename .csv to .txt and then open in Excel. To prevent Excel from automatically changing the data format to number/date format,...
Read more >
Date format incorrect on CSV user upload - Zendesk help
When bulk importing users into Zendesk through CSV upload, the dates are formatted incorrectly. Microsoft Excel changes the date format.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found