收集的得到excel表格中数据的几个简单的方法,希望对大家得开发有帮助:
1.
insert into test
select * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0','Data Source= e:/zhongwenbeijing.xls;Extended Properties=Excel 8.0')...[sheet1$]
2.
select * into test from openrowset('MicroSoft.Jet.OleDB.4.0','Excel 5.0;HDR=yes;imex=1;Database=c:/test.xls',sheet1$)
3.
/// <summary>
/// 由EXCEL转换成DataTable
/// </summary>
/// <param name="strpath"> 文件路径及文件名 </param>
/// <returns> </returns>
private DataTable XlsToDataTable(String strpath)
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + strpath + ";" +
"Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
DataTable dt = new DataTable();
myCommand.Fill(dt);
return dt;
}