Handling changes in column order when importing CSV files
Posted
by Scott
on Stack Overflow
See other posts from Stack Overflow
or by Scott
Published on 2010-03-16T16:05:59Z
Indexed on
2010/03/16
16:21 UTC
Read the original article
Hit count: 230
I have a CSV file. The first row will always contain column headers. Depending on a variety of factors, the order of columns may change and, in rare circumstances, some columns may not be present. These changes are beyond my control.
My thoughts, so far, on how to address this. I'll read the first row of the file and use the values to generate a list of columns contained in the source file. The destination file will use the same column names as the source. This should be as simple as searching for identical names in the source and destination, then just mapping the column index values, right?
What are your recommendations for handling this?
© Stack Overflow or respective owner