[样本.xlsx]
Column 0, Row 0 = "ItemA"
Column 0, Row 1 = "ItemB"
Column 0, Row 2 = "ItemC"
Column 0, Row 3 = "ItemD"
[应用]
DataSet dsData = new DataSet();
string strConn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Sample.xlsx;Extended Properties='Excel 12.0;'";
OleDbDataAdapter daGetExcel = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
daGetExcel.Fill(dsData);
foreach (DataRow row in dsData.Tables[0].Rows)
{
lbExcelData.Items.Add(row[0].ToString());
}
lbExcelData
是窗体上的 ListBox 控件。
[结果]
“项目B”、“项目C”、“项目D”
[问题]
为什么第一项“ItemA”被忽略?