asp.net导入excel转为datatable
时间:2010-11-19 来源:宏-cai
<asp:FileUpload runat="server" ID="fupFiles" Width="300px" />
excel表名<asp:TextBox ID="txtSheet" runat="server">Sheet1</asp:TextBox>
//表名为excel左下角的表名,默认为sheet1,sheet2,...
2 后台:
string excelName = txtSheet.Text;
string excelPath= fupFiles.PostedFile.FileName; string strConn; strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); OleDbDataAdapter oada = new OleDbDataAdapter ( "select * from [" + sheetname + "$]", strConn ); DataTable dt = new DataTable(); try { oada.Fill(dt);//获得datatable } catch( Exception ex) { }
相关阅读 更多 +