is there a good and free implementation of CSV parser available under some liberal licence? Some counterpart of SuperCSV for Java, perhaps a port?
Jawaban:
Ada implementasi yang bagus di CodeProject :
Untuk memberikan lebih banyak angka yang membumi, dengan file CSV 45 MB yang berisi 145 bidang dan 50.000 catatan, pembaca memproses sekitar 30 MB / detik. Jadi secara keseluruhan, butuh 1,5 detik! Spesifikasi mesin adalah P4 3.0 GHz, 1024 MB.
Microsoft.VisualBasic.FileIO.TextFieldParseSudah mencoba dan berhasil.
Anda dapat memuat file CSV ke DataTable.
Kode sampel -
static DataTable CsvToDataTable(string strFileName)
{
DataTable dataTable = new DataTable("DataTable Name");
using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + Directory.GetCurrentDirectory() + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\""))
{
conn.Open();
string strQuery = "SELECT * FROM [" + strFileName + "]";
OleDbDataAdapter adapter =
new System.Data.OleDb.OleDbDataAdapter(strQuery, conn);
adapter.Fill(dataTable);
}
return dataTable;
}
Pastikan Anda mengkompilasi proyek Anda ke prosesor x86. Tidak berfungsi untuk x64.
try filehelpers Work amazingly well. I am using it to parse a 100 MB file every day.
Have you tried the FileHelpers library? It's free, open source and can be used to parse CSV files.
I've started using CSV Parser that is part of the CommonLibrary.NET.
It uses .NET 3.5, has an easy API, and convenient overloads/methods & lamda's for iterations.
I don't have any benchmarks for this one like above, but nice thing about this is that it's just one component of a library similar to Java Commons. So I also get a Command-line parser, Repository implementation among other things.