欢迎光临
我们一直在努力

Accessing an Excel Spreadsheet in ASP.NET (VB and C#) by Alex Lowe-.NET教程,数据库应用

建站超值云服务器,限时71元/月

c# code
———————————————
<%@ page language="c#" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.ado" %>

<script language="c#" runat="server">
protected void page_load(object src, eventargs e)
{
string strconn;
strconn = "provider=microsoft.jet.oledb.4.0;" +
"data source=c:\\exceltest.xls;" +
"extended properties=excel 8.0;";
you must use the $ after the object you reference in the spreadsheet
adodatasetcommand mycommand = new adodatasetcommand("select * from [sheet1$]", strconn);

dataset mydataset = new dataset();
mycommand.filldataset(mydataset, "excelinfo");
datagrid1.datasource = mydataset.tables["excelinfo"].defaultview;
datagrid1.databind();
}
</script>
<p><asp:label id=label1 runat="server">spreadsheet contents:</asp:label></p>
<asp:datagrid id=datagrid1 runat="server"/>

vb.net code
———————————————-
<%@ page language="vb" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.ado" %>

<script language="vb" runat="server">
sub page_load(sender as object, e as eventargs)
dim mydataset as new dataset()

you can also use the excel odbc driver i believe – didnt try though
dim strconn as string = "provider=microsoft.jet.oledb.4.0;" & _
"data source=c:\exceltest.xls;" & _
"extended properties=""excel 8.0;"""

you must use the $ after the object you reference in the spreadsheet
dim myadodatasetcommand as new adodatasetcommand("select * from [sheet1$]", strconn)
myadodatasetcommand.tablemappings.add("table", "exceltest")
myadodatasetcommand.filldataset(mydataset)

datagrid1.datasource = mydataset.tables(0).defaultview
datagrid1.databind()
end sub
</script>
<p><asp:label id=label1 runat="server">spreadsheet contents:</asp:label></p>
<asp:datagrid id=datagrid1 runat="server"/>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » Accessing an Excel Spreadsheet in ASP.NET (VB and C#) by Alex Lowe-.NET教程,数据库应用
分享到: 更多 (0)

相关推荐

  • 暂无文章