Forum Moderators: coopster

Message Too Old, No Replies

parsing .csv files

         

StoutFiles

2:01 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I wrote a parser for work that pulls data out of a .csv file. However, different versions of Excel create different types of .csv files. If I have 3 rows and 10 columns...

Excel 97:

, , , 345, 435, 231, 453

, , , 127, 432, 345, 876

Excel 07:

, , , 345, 435, 231, 453, , , ,
, , , , , , , , , ,
, , , 127, 432, 345, 876, , , ,

I need to make the file format like Excel 97 .csv before I start parsing. How could I remove the extra commas from the 07 .csv format? The number of rows and columns will be constantly changing.

jatar_k

2:39 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I don't see any need to change it

>> The number of rows and columns will be constantly changing.

not sure why that matters.

from a parsing standpoint an empty row is skipped and so is a row of empty values, the missing values at the end of the rows should be testable as well

if (isset($myvar) && !empty($myvar)) {
// then do stuff
} else {
// don't do the stuff
}

StoutFiles

2:58 pm on Apr 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I ended up fixing the parser to ignore all extra commas.