0
我一直在研究桌面应用程序,并且在导入Excel文件时遇到了一些问题。Excel文件导入 - 数据类型
一切都很好,但是当我从Excel工作表读取数据时,它并没有读取所有的数字和字母。例如,如果该列的第一个单元格是数字,则不会从该列读取字母。如果我手动将该类型更改为该文本,那么一切都很好。
这是我的示例代码导入Excel工作表数据。
任何想法?
public static DataSet exceldata(string filelocation)
{
DataSet ds = new DataSet();
OleDbCommand excelCommand = new OleDbCommand();
OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
string excelConnStr = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 4.0;HDR=YES;IMEX=1;Importmixedtypes=text;typeguessrows=0;\"", filelocation);
OleDbConnection excelConn = new OleDbConnection(excelConnStr);
excelConn.Open();
DataTable dtPatterns = new DataTable();
excelCommand = new OleDbCommand("SELECT * FROM [Sheet1$]", excelConn);
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(dtPatterns);
ds.Tables.Add(dtPatterns);
return ds;
}