110,538
社区成员
发帖
与我相关
我的任务
分享
private DataSet ExecleDs(string SheetName, string filenameurl, string table)
{
string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filenameurl + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter odda = new OleDbDataAdapter("select * from [" + SheetName + "]", conn);
odda.Fill(ds, table);
conn.Close();
return ds;
}
DataSet ds = ExecleDs(SheetName, savePath, filename,); //调用自定义方法
DataRow[] dr = ds.Tables[0].Select(); //定义一个DataRow数组
int rowsnum = ds.Tables[0].Rows.Count;
//判断是否有数据
if (rowsnum == 0 )
{
return;
}