ASP.NET:Dispaly data from an EXCEL spreadsheet

Source: Internet
Author: User
Asp.net|excel This code is written in response to a, posted on one of Charles Carroll ' s asp.net lists. Can sign up for one or all of the lists. This page provides a simple example of the how to query an EXCEL spreadsheet the from a asp.net page using vb.net.

Code:

<%@ Page language= "VB"%>
<%@ Import namespace= "System.Data"%>
<%@ Import namespace= "System.Data.OleDb"%>
<script language= "VB" runat= "Server" >
Sub Page_Load (sender as Object, E as EventArgs)
Dim myDataSet as New DataSet ()

Dim strconn as String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data source=" & Replace (Server.MapPath ("."), "\", "\") & "\\exceltest.xls" & _
"Extended properties=" "Excel 8.0;" ""

' You must use the ' $ after the ' object for your reference in the spreadsheet
Dim Myoledbdataadapter as New oledbdataadapter ("select * from [sheet1$]", strconn)
Myoledbdataadapter.fill (myDataSet)

DataGrid1.DataSource = mydataset.tables (0). DefaultView
Datagrid1.databind ()
End Sub
</script>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.