前台代碼
<asp:FileUpload runat=server ID=fupFiles Width=px />excel表名<asp:TextBox ID=txtSheet runat=server>Sheet</asp:TextBox>//表名為excel左下角的表名默認為sheetsheet
後台
string excelName = txtSheetText;
string excelPath= fupFilesPostedFileFileName;
string strConn;
strConn = Provider=MicrosoftJetOLEDB;Data Source= + filepath + ;Extended Properties=Excel ;;
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter oada = new OleDbDataAdapter ( select * from [ + sheetname + $] strConn );
DataTable dt = new DataTable();
try {
oadaFill(dt);//獲得datatable
}
catch( Exception ex) { }
From:http://tw.wingwit.com/Article/program/net/201311/12008.html