在C#中如何使用OLEDB访问Excel标头(不使用自动化)? [英] In C# how to access excel headers using OLEDB (without Automation)?
本文介绍了在C#中如何使用OLEDB访问Excel标头(不使用自动化)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我尝试访问第一行,第一列的代码
This is my code where I am trying to access first row, first column
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + fileName + @";Extended Properties=""Excel 8.0;HDR=NO;""";
string CreateCommand = "SELECT * FROM [Sheet1$]";
OleDbConnection conn = new OleDbConnection(connectionString);
conn.Open();
OleDbCommand cmd = new OleDbCommand(CreateCommand, conn);
// cmd.ExecuteNonQuery();
DbDataReader dr= cmd.ExecuteReader();
int i = 0;
while (dr.Read())
{
string ab = dr.GetValue(i).ToString();
MessageBox.Show(ab);
i++;
}
推荐答案
您是否尝试过HDR = YES?这就是告诉OLEDB提供者您确实有标题行的原因.
Did you try HDR=YES ? That's what tells the OLEDB provider that you do have a header row.
http://connectionstrings.com/excel
这篇关于在C#中如何使用OLEDB访问Excel标头(不使用自动化)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文