不可能慢.我曾经读过一个10万行的excel,一个sheet都装不下.都是分页装的.也是一瞬间就读进内存了.以下是读excel到DataTable中的方法
public DataTable GetExcel(string Path)//Excel导入到DataSet
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties='Excel 8.0;HDR=YES;IMEX=1';";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = null;
DataTable dt = new DataTable();
int result = 1;
try
{
conn.Open();
DataTable dtName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
string strExcel = "Select * from [" + dtName.Rows[0]["TABLE_NAME"].ToString() + "]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
myCommand.Fill(dt);
conn.Close();
}
catch (Exception ex)
{
result = 2;
}
finally
{
conn.Close();
}
if (result == 2) return null;
else return dt;
}
获取第一行第一列
DataTable dt = GetExcel(excelpath);
dt.Rows[0][0].ToString();