首页 > 编程 > .NET > 正文

ASP.NET: Dispaly data from an Excel Spreadsheet

2024-07-10 13:03:29
字体:
来源:转载
供稿:网友
this code was written in response to a message posted on one of charles carroll's asp.net lists. you can sign up for one or all of the lists here.this page provides a simple example of how to query an excel spreadsheet from an asp.net page using vb.net.

code:

<%@ page language="vb" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.oledb" %>
<html>
<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 you 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>
</html>

菜鸟学堂:
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表