CategoriesQuicksearchSponsored LinksCurrently... |
Monday, September 12. 2005CSV file parser and writer in C# (Part 2)Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Hi there, thank you so much for your interesting code (*CSV file parser and writer in C#*). But is there a way to read a .CSV file and store all the data into 1d array rather than using DataTable.
Hello!
You can use the DataTable as a two-dimensional array if you want. For example, to get the element in row 5, column 10 you write: table.Rows[5][10] If you do need an actual array, you could loop over the DataTable and fill an array this way as well.
This code works great. Is it ok to use it in a commercial application?
Yes, you can use this code in a commercial application, no guarantees, warranties etc. though
Actually did you thought of assigning a license to it? To trial attorneys, saying others can use in commercial application doesn't really mean that one wouldn't try to collect royalty or impose conditions.
*New BSD license *MIT license And definitely you can pick other more elaborated or public domain (no need for license). A good resource is http://www.opensource.org/licenses/category,
Good suggestion. I'll repackage it and add a license once I've had a chance to look at a few.
Nice code. Saved me a fair chunk of time writing my own from scratch:)
Cheers.
Thats great code. Exactly what I was looking for. Thanks for this!
I tried the code it and it works fine!
Can this parser be used to parse a tab delimited CSV file? I tried it and it didnt work. Any tweak required?
Pls. dont bother. I figured it out. Thanks for the excellent code. It helped a lot. I added the following condition
if ((postdata || !quoted) && (c == ',' || c == '\t')) Let me know if anything else needs to be done. It worked well though so far. Haven't tested it enough.
Very nice, and as far as I can tell from the first look flawless code. I have seen quite a few csv readers based on regular expressions, but they all seemed to miss at least one aspect of the csv specification.
Hi. Really nice program. Im having problem with flawed csv with newline in an cell that isnt inclosed in "". Ive tried adding "" manually but cant get it to work.
I was having problems with the Jet ODBC engine only loading 255 columns from a csv file, this saved me a bunch of time over writing my own parser. Thanks for the link to csv spec too, I always wondered how it handled line breaks mid-record...
Nice job. Found a bug: If the last "cell" in the file is an empty string it's ignored. (IE, "1,2,3,4," would return 4 elements instead of 5, with the 5th element being just an empty string)
I modified CsvStream.GetNextRow() to resolve this. Modified the "if (EOL)" block to this: if (EOL || EOS) { EOL = false; EOS = false; return null; } and in the loop, modified the "if (EOS)" block to this: if (EOS) return item.ToString(); (got rid of "return item.Length > 0 ? item.ToString() : null;")
COde Not working...
if csv file has any unsigned values like / or blank space the loop break at that point.. so not validated
Hi.
This is a great article, but could you show some example code how to call the example code from main? I'm thinking of having some line to open file "a.csv" in the current directory. Is this code meant to be run from Command Prompt, or some other way, such as through Excel? Or is it part of a VSTO project or something? Thanks.
This looks like excellent work, and is just what I needed. Added to StumbleUpon
I am able to create/write/save csv file .
excellent code. But I need further assistance as to saving that csv file in a particular type. Currently my file is being saved as "CSV(Comma delimited) (*.csv). But i would like to save it as CSV(MS-DOS)(*.csv). Please let me know. |
My del.icio.us
LicenseBlog Administration |