C#读取Excel的数据,并且以混合模式读取,防止数据类型变更

        /// <summary>
/// Read Excel to DataSet
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
private static DataSet ExcelToDataSet(string filename)
{
DataSet ds;
//HDR=Yes;IMEX=1 HDR隐藏Excel表头 IMEX是以混合模式读取Excel表格数据,防止改变数据类型
string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filename + ";" + "Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';";
System.Data.OleDb.OleDbConnection myConn = new System.Data.OleDb.OleDbConnection(strCon);
string strCom = " SELECT * FROM [Sheet1$]";
myConn.Open();
System.Data.OleDb.OleDbDataAdapter myCommand = new System.Data.OleDb.OleDbDataAdapter(strCom, myConn);
ds = new DataSet();
myCommand.Fill(ds);
myConn.Close();
return ds;
}
上一篇:MVC和传统的以模板为中心的web架构比较


下一篇:ASP.NET Core 1.0 Configuration 配置管理