+ Reply to Thread
Results 1 to 8 of 8

Reading CSV text files

  1. #1
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Reading CSV text files

    I have this code that will read data from a csv file and put it in my excel sheet. However, could the code do 2 more things (listed in priority)?? 1. Start reading the file at the 3rd line, and only read every other line after that and 2. parse the data into separate columns based on the comma delimeter. I read somewhere that you could read the data into an array then loop the array into the columns to delimit it, but i don't know how to do that. Here is the code....thank you!!!!
    Please Login or Register  to view this content.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Reading CSV text files

    I would do it this way
    Please Login or Register  to view this content.
    Last edited by pike; 02-21-2010 at 06:58 AM.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Reading CSV text files

    I think this approach is easier for a novice to understand.
    Note the texttocolumns function can be used manually from the spreadsheet

    The textToColumns can be preset to state what sort of data is in which columns. I have left this on automatic. If it causes a problem you will need to post some data and I (or somone) will help you with that.

    Please Login or Register  to view this content.


    click on the * Add Reputation if this was useful or entertaining.

  4. #4
    Forum Contributor
    Join Date
    02-20-2007
    MS-Off Ver
    2003 & 2007
    Posts
    299

    Re: Reading CSV text files

    Thankyou...Pikes example worked well, I incorporated the comma delimit aspect of tony h's example. Follow up question, How can you read just the last line of a file?

  5. #5
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187

    Re: Reading CSV text files

    It depends on what and why you are trying to do it.

    The simplest way is to use the same code as below to read through the file and just keep the last value.
    The fastest way is more complicated. You open the file in block mode and read and interpret the last blocks. It helps to know what the maximum line length is. Because of the variations this is more complex to programme.

    Note: if you are just trying to keep the last line of a file you are reading anyway the code below can be altered to make this available.

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Reading CSV text files

    Yep thats why I use the collection you can use the data again
    Just go to the last value in the collection

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Reading CSV text files

    That might be a lot of data to store, Pike, unless you have good reason to store it.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Reading CSV text files

    True, I usually extract all the good stuff , do the calx and just store the results

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1