熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net導入excel轉為datatable

2022-06-13   來源: .NET編程 

   前台代碼

  <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
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.