How to read excel cvs file from C#

  • Thread starter Thread starter Andy Lee
  • Start date Start date
A

Andy Lee

Could someone tell me how I can read excel csv (comma separated variable)
file using C#? I know how to do it by parsing each line myself. Since
reading excel csv file in C# is a pretty common technique, I just wonder
whether there is a class or a way to do it out there already.

Thanks,

Andy
 
What are you trying to read the file into? Are you trying to open it programmatically into an instance of an Excel Worksheet or just into an array type structure

Thanks

Travis Merke
(e-mail address removed)
 
I tried to read a .CSV file into an array of string. I can use the
string.split method to do it if the .CSV file just contain "," without
quotas. But if there is quota, split function can't handle it. For
example, file like this
1234,"546,345",564
should be split into three pieces. But split function will make it four
pieces. Also if a cell in excel has data like
sgs"gdfgs"sdfsd
it is stored as
"sgs""gdfgs""sdfsd
I would like to see
sgs"gdfgs"sdfsd
when it is read into an string.

Thanks,

Andy
 
Use RegularExpression matches to parse it, that way you can match both
situations you described.
 
Back
Top