开发者

Read from excel file with square brackets in header C#

I'm trying to read from excel file with oleDB provider using 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?

Thank you for your help!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜