有没有比
更好的方法string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=<xlxsName>;Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;ReadOnly=True\"";
string sql = string.Format("SELECT COUNT (*) FROM [{0}] ", worksheetName);
using (OleDbConnection conn = new OleDbConnection(connectionString)) {
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
totalCount = (int)cmd.ExecuteScalar();
conn.Close();
}
从excel表中获取行数?如果可能的话,我宁愿使用ADO.Net而不是Excel interop