下面的代码片段可以很好地读取5000-6000行,但不能超过10000行。当我使用SELECT * FROM Sheet1 $ A1:DC20000时,dtdata只有8327行。
string connstr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + templatepath + ";Extended Properties=Excel 12.0;";
string Extension = Path.GetExtension(templatepath);
if (Extension == ".xls")
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + templatepath + ";Extended Properties=Excel 8.0";
OleDbConnection conn = new OleDbConnection(connstr);
strSQL = "SELECT * FROM Sheet1$A1:DC20000";
OleDbCommand cmd = new OleDbCommand(strSQL, conn);
cmd.CommandTimeout = 5000;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(dtdata);
dtdata.TableName = "Table0";
dsdata.Tables.Add(dtdata);