Jump to content


Photo

CSV To Array


  • Please log in to reply
6 replies to this topic

#1 doublet216

doublet216

    Member

  • Members
  • PipPip
  • 10 posts

Posted 04 March 2013 - 01:00 AM

I am stuck getting a CSV file that I upload into an array in javascript.   So far my file upload gives me.

 

param_name,param_val "name2","value2" "name","value" "name1","value1"

 

I need to just grab the values inside the " ".  So I would need an array to go like

 

array(

[0] name2 => value 2

[1] name => value

[2] name1 => value 1

)

 

I am stuck and can't seem to get it how I need it.   Can anyone help? I have tried replacing and splitting but with no such luck.  Any push in the right direction is appreciated. 

 

 

 

My Excel CSV looks like this

 

param_name | param_val

name 2          | value2

name             | value

name1           | value1



#2 haku

haku

    Advanced Member

  • Gurus
  • 6,172 posts

Posted 04 March 2013 - 01:55 AM

Is the .csv file a single line exactly as you are showing it?

#3 doublet216

doublet216

    Member

  • Members
  • PipPip
  • 10 posts

Posted 04 March 2013 - 10:18 AM

its an excel document with 2 columns and 4 rows.

 

param_name |  param_val

name 2          |  value2

name             |  value

name1           |  value1



#4 haku

haku

    Advanced Member

  • Gurus
  • 6,172 posts

Posted 04 March 2013 - 10:41 AM

Excel files are binary and cannot be parsed as text.

#5 doublet216

doublet216

    Member

  • Members
  • PipPip
  • 10 posts

Posted 04 March 2013 - 10:52 AM

even if .csv



#6 .josh

.josh

    Grumpy Old Man

  • Administrators
  • 13,834 posts
  • LocationWhere You Live.

Posted 04 March 2013 - 12:19 PM

If you save as .csv then each row should look like

 

 

value1,value2

 

or 

 

"value1","value2"

 

 

..but you are showing pipes...are you just using pipes in your post or is that what you really have in your file? 

 

in any case...are you sure this is javascript you are talking about?  javascript cannot read files...well, I guess if you have an ActiveX object...is that what you have?  Or are you uploading the file and then using php or some other server-side language to respond w/ the contents (i.e. ajax)?  IOW, how are you opening the file and getting the data to javascript? 


Posted Image
Did I help you? Feeling generous? Donate to me! || Donate to phpfreaks!


#7 haku

haku

    Advanced Member

  • Gurus
  • 6,172 posts

Posted 04 March 2013 - 06:23 PM

If you save it as a .csv file, it's not an excel file anymore, and we are back to my original question of what the actual text looks like. But that all said, all the questions raised in the last post are relevant.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com