怎样在asp.net中读取Excel文件中表格的内容
有个Excel文件,保存的是员工信息,怎样将数据读入到.net的DataTable中
------解决方案-------------------- strConn = "Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=Server.MapPath(@ "excelFilePath ");Extended Properties=Excel 8.0; ";
string strSqlCommand = " ";
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn);
conn.Open();
DataTable schemaTable = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, null);
//获取excel表中的工作簿信息表
//schemaTable.Rows.Count为excel中工作簿数目
for(int i=0; i <schemaTable.Rows.Count; i++)
{
DataTable dtTemp = new DataTable();
strSqlCommand = "SELECT * FROM [ "+schemaTable.Rows[i][ "TABLE_NAME "].ToString()+ "] ";
System.Data.OleDb.OleDbDataAdapter myCommand = new System.Data.OleDb.OleDbDataAdapter(strSqlCommand, conn);
myCommand.Fill(dtTemp);
conn.Close();
}
------解决方案--------------------上面的是对的!