本地读取Excel没事上传服务器IIS上读取DataTable就等于null
本地是wps 8.0 服务器上的Excel是2013
文件能上传到服务器 就是无法读取到excel里面的内容 本地测试是完全没问题的
麻烦前辈帮忙分析一下
DataTable dt = new Helps().GetExcelData(path);
public System.Data.DataTable GetExcelData(string strPath)
{
System.Data.DataTable dt = new System.Data.DataTable();
try
{
DataSet ds = new DataSet();
//string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strPath + ";" + "Extended Properties=Excel 8.0;";
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1';";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
OleDbDataAdapter myCommand = null;
string strExcel = "select * from [Sheet1$]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(dt);
conn.Dispose();
}
catch (Exception ex)
{
ex.ToString();
dt = null;
}
return dt;
}