CSV

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff Thies

    CSV

    I'd like to to read a CSV file with javascript. (put into an array of
    arrays). (The CSV file would be imported from a input type="file")


    I'm not sure how to go about this. Hairy regex or some functions based on
    iterating through every character?

    Anyone done this in javascript? Hints?

    Jeff


  • Tim Williams

    #2
    Re: CSV

    You don't say where you're doing this (server/client browser/WSH?), so
    it's difficult to know what might be the best way.

    Simplest would be to read in the whole file using the FSO and split
    into an array based on the line separator, then iterate through that
    array splitting each line into its constituent fields. Watch out for
    quoted fields where the value contains a comma. If the line has no
    quotes then you can just split on comma, otherwise a regexp or
    character-by-character iteration might do it.

    You might also try using the "text" ADO driver and just do a "select
    all" on the file.


    Tim.




    "Jeff Thies" <nospam@nospam. net> wrote in message
    news:mIjAc.3898 $bs4.792@newsre ad3.news.atl.ea rthlink.net...[color=blue]
    > I'd like to to read a CSV file with javascript. (put into an array[/color]
    of[color=blue]
    > arrays). (The CSV file would be imported from a input type="file")
    >
    >
    > I'm not sure how to go about this. Hairy regex or some functions[/color]
    based on[color=blue]
    > iterating through every character?
    >
    > Anyone done this in javascript? Hints?
    >
    > Jeff
    >
    >[/color]


    Comment

    • Jeff Thies

      #3
      Re: CSV


      "Tim Williams" <saxifraxREMOVE @THISpacbell.ne t> wrote in message
      news:ETmAc.1070 $O02.350@newssv r25.news.prodig y.com...[color=blue]
      > You don't say where you're doing this (server/client browser/WSH?), so
      > it's difficult to know what might be the best way.
      >[/color]
      It's client side.


      I've just about got it written, quoted commas were a small problem, quoted
      linefeeds took a bit more work. It's about 1K of code and I'll post it up if
      anyone is interested.

      Cheers,
      Jeff

      [color=blue]
      > Simplest would be to read in the whole file using the FSO and split
      > into an array based on the line separator, then iterate through that
      > array splitting each line into its constituent fields. Watch out for
      > quoted fields where the value contains a comma. If the line has no
      > quotes then you can just split on comma, otherwise a regexp or
      > character-by-character iteration might do it.
      >
      > You might also try using the "text" ADO driver and just do a "select
      > all" on the file.
      >
      >
      > Tim.
      >
      >
      >
      >
      > "Jeff Thies" <nospam@nospam. net> wrote in message
      > news:mIjAc.3898 $bs4.792@newsre ad3.news.atl.ea rthlink.net...[color=green]
      > > I'd like to to read a CSV file with javascript. (put into an array[/color]
      > of[color=green]
      > > arrays). (The CSV file would be imported from a input type="file")
      > >
      > >
      > > I'm not sure how to go about this. Hairy regex or some functions[/color]
      > based on[color=green]
      > > iterating through every character?
      > >
      > > Anyone done this in javascript? Hints?
      > >
      > > Jeff
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...