因此,我尝试使用此代码从excel文件读取数据,但DataTable返回零行,它不会给出任何错误,只是一个空的DataTable。请帮忙。
public DataTable ReadExcel(string fileName)
{
string conn = string.Empty;
DataTable dtExcel = new DataTable();
conn = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" fileName + ";Extended Properties='Excel 12.0;HDR=NO';";
using (OleDbConnection con = new OleDbConnection(conn))
{
try
{
OleDbDataAdapter oleAdpt = new OleDbDataAdapter("select * from [sample$]", con);
oleAdpt.Fill(dtExcel);
}
catch { }
}
return dtExcel;
}