2017-02-17 57 views

回答

1

當然你可以做到這一點。使用FileHelpers class builder在運行時構建導入規範。例如:

// create a FileHelpers class with a comma delimiter. 
DelimitedClassBuilder cb = new DelimitedClassBuilder("Person", ","); 
// add your fields based on whatever logic you like (e.g., maybe read the column names from the first row) 
cb.AddField("firstName", typeof(string)); 
cb.AddField("lastName", typeof(string)); 
cb.LastField.FieldNullValue = "default last name"; 

// create your import engine from the class you created above. 
DelimitedFileEngine engine = new DelimitedFileEngine(cb.CreateRecordClass()); 
DataTable dt = engine.ReadFileAsDT("data.csv"); 
相關問題