shancarter / mr-data-converter

Takes CSV or tab-delimited data from Excel and converts it into several web-friendly formats, include JSON and XML.
http://shancarter.github.com/mr-data-converter/
Other
1.96k stars 776 forks source link

PHP: Numbers that are a string #9

Open ursbraem opened 11 years ago

ursbraem commented 11 years ago

Hi!

First let me say that Mr. Data Converter is super awesome. Thanks a lot!

I've had an issue when pasting the following code from Excel:

Tag/e Monat/e Jahr Veranstaltung Organisator Referatstitel Ort 14-15 8 2007 Event Stadt Zürich Title Zürich

The first value is a string. But it looks like a calculation. What Mr. D gives back is:

array("val0"=>14-15,"val1"=>8,"val2"=>2007,"val3"=>"Zürcher Ferienpass","val4"=>"Stadt Zürich","val5"=>"Dein Handy und die Technik","val6"=>"Zürich"),

And what PHP gives back for $row['val0'] is: -1 because it does the math for 14-15.

Would it therefore make sense to be able to add double quotes around each value, also numeric ones?

mbbender commented 11 years ago

Same issue here.

Abromeit commented 10 years ago

[Update] Current situation in the Demo:

thdoan commented 9 years ago

There is another scenario to consider: postal codes. For example, I'm converting a sheet with a postal code column that contains the value "0800" (a postal code in Australia). The converted JSON property is "postcode":0800, which is invalid. Please provide an option to quote all values, even when the string is all numbers.

victor-t commented 7 years ago

@thdoan In my situation, UPC code starts with zeros some times. I forked a copy and commented out a few lines. in js/CSVParser.js

  //---------------------------------------
  // UTILS
  //---------------------------------------

  isNumber: function(string) {
//  if( (string == null) || isNaN( new Number(string) ) ) {
      return false;
    },
//   return true;
 // },

You could probably deleted the whole thing but basically it returns false all the time so it never tries to parser into numbers/int

I would add an option to turn this off and on though. But this was a quick and easy way to change the tool to get the same results.

thdoan commented 7 years ago

@victor-t I fixed this long back, along with a few other enhancements in my fork.

victor-t commented 7 years ago

@thdoan I figured but just incase ;) i'll take a look at your fork cause i just recently started using this.