Import/export Excel worksheet in ASP.NET (CSASPNETExcelImportExport)

The code sample demonstrates importing and exporting Excel worksheet in ASP.NET

C# (49.8 KB)
4.1 Star
60,685 times
Add to favorites
E-mail Twitter Digg Facebook
Sign in to ask a question

  • Please look into it
    2 Posts | Last post July 12, 2013
    • Hi,
      Suppose I have exported an excel sheet then, if I add another row to the exported excel sheet and try to import the same to the database, it does not import the newly added row while the remaining rows are imported successfully.
      Can anyone help me?
    • I also tried the same thing. But in my case, it was some other kind of error I faced. The 'Import Sheet' relies on the default worksheet name i.e. Sheet1 whereas the exported file will have some other worksheet name most of the times (generally same as the file name). So, when I edited the exported file and tried to import it back, it faced some internal error. I got no way to change or reset the worksheet name while exporting a .xls or .xlsx file.
  • problems
    3 Posts | Last post March 15, 2013
    • I use the code and I just adjust it but i can found why it didn't work? this is the error it shows : "The Microsoft Jet database engine could not find the object 'dbo.Prueba'.  Make sure the object exists and that you spell its name and the path name correctly." dbo.Prueba is my table and I change the security on it so I can write on it but nothing happens it keep telling the same I don't know what to do. here is my code 
      ' Retrieve data from the Excel spreadsheet. 
          Protected Function RetrieveData(strConn As String) As DataTable
              Dim dtExcel As New DataTable()
              Using conn As New OleDbConnection(strConn)
                  ' Initialize an OleDbDataAdapter object. 
                  Dim da As New OleDbDataAdapter("SELECT name, phone FROM [dbo.Prueba]", conn)
                  ' Fill the DataTable with data from the Excel spreadsheet. 
              End Using
              Return dtExcel
          End Function
    • Dim da As New OleDbDataAdapter("SELECT name, phone FROM [Sheet1$]", conn)
    • Nice sample
  • The zip file can't be uncompress
    2 Posts | Last post December 09, 2011
    • I have downloaded the, but I get the error when I try to unzip the file with WINZIP 11.2, could you help me? Thanks!
      Access to see error info.
    • You can use win.rar to unpack.
  • Is this x86 (32-bit) example only?
    2 Posts | Last post December 09, 2011
    • When I've tried something similar a few years ago, getting data from Excel through OleDb 
      was not working on x64 systems (Windows  Server 2003 R2 x64).
      Has this changed? If it works only on 32-bit systems, please mark this sample as such.
      And I would suggest this for other samples also: by default - it works on both 
      architectures, and if it works on one architecture - please, mark it as such.
      And please, don't forget about ARM and Windows 8: maybe some of the 
      samples don't work on this new platform and I'd like to know about that BEFORE trying them out.
    • Works on my x64 environment.
  • 建议
    1 Posts | Last post June 30, 2011
    • string strExtension = Path.GetExtension(strFileName);
      Response.Write("<script>alert('Please select a Excel spreadsheet to import!');</script>");