Read from excel file with square brackets in header C#
using (v开发者_StackOverflow社区ar fileConnection = new OleDbConnection(fileConnectionString))
{
var command = new OleDbCommand(@"Select SourceName, [ExternalID] FROM [page1$]", fileConnection);
fileConnection.Open();
var reader = command.ExecuteReader();
while (reader.Read())
{
yield return new Source
{
//some code
};
}
}
. The only problem is that some headers in excel file have a square bracket in their name like [ExternalID]
. Is it possible to read them? How can I do it?
Its simple. Create an excel doc which contains column called [ExternalId] and try get value. If you cant get that column value, use Adapter to get whole excel, and then you can find [ExternalID] column index. The index is what you need to get values.
精彩评论