将Excel数据导入到C#而没有第一行成为列名? [英] Importing Excel data into C# without first row becoming column names?
本文介绍了将Excel数据导入到C#而没有第一行成为列名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用c#将excel中的数据导入到datatable中。这是我使用的代码...
I am trying to import data from excel into a datatable using c#. Here is the code I use to do so...
string ConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + fileName + "; Jet OLEDB:Engine Type=5;" +
"Extended Properties=\"Excel 8.0;HRD=No;IMEX=1;\"";
OleDbDataAdapter SheetAdapter = new OleDbDataAdapter("select * from ["Sheet1"]", conn);
System.Data.DataTable excelData = new System.Data.DataTable();
SheetAdapter.Fill(excelData);
excelData.TableName = "excelData";
foreach (DataRow row in excelData.Rows)
{
ProcessDataRow(row);
}
当我查看datatable时调试第一行数据已经成为表列名。当我将HDR = No连接到连接字符串中时,我不明白为什么会发生这种情况。有没有办法强制DataTable不将第一行作为列名?
When I look at the datatable while debugging the first row of data has become the tables column names. I don't understand why this is happening when I put HDR=No into the connection string. Is there a way to force the DataTable to not take the first row as column names?
推荐答案
您提供的代码示例有 HRD = No
而不是 HDR =否
The code sample you provided has HRD=No
instead of HDR=No
这篇关于将Excel数据导入到C#而没有第一行成为列名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文