读取Excel中的数据到DataSet
1、引用命名空间
using System.Data.OleDb;
2、输入Excel文件,输出DataSet
public DataSet ExecleDs()
{
string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\data-for-source-apportionment\\PM-SO2-NOx-CO-O3-201311-20140324.xlsx;Extended Properties=‘Excel 12.0;HDR=YES‘";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [ConcHourCSV$]", conn);
DataSet ds = new DataSet();
odda.Fill(ds);
return ds;
}
时间: 2024-10-13 19:03:26