在ASP.NET访问Excel文件 (VB and C#)
2006-03-07 17:03:32 来源:WEB开发网核心提示: C# Code - <%@ Page Language="C#" %> <%@ Import Namespace="System.Data" %> <%@ Import Namespace="System.Data.AD
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"/>
---------------------------------------------
<%@ 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"/>
- ››asp.net页面弄成伪静态页面
- ››Asp.net 中将汉字转换成拼音的方法
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
更多精彩
赞助商链接