当前位置: 首页 > 图文教程 > 网络编程 > ASP > ASP.NET:访问Excel 电子表格

ASP
bbs的树状结构算法
bbs的树状算法的补充程序
ASP.NET:访问Excel 电子表格
ADO.NET:ADODataReader类
ADO.NET:使用ADO.NET连接文本文件
session变量中的数组如何引用
外源.js的选择调用与一个.htm网站管理初探
验证email地址是否合法完整实例
不用Global.asa实现在线人数统计
为输入及输出的数据库的资料做造型
改进性能和样式的 25+ ASP 技巧(1)
改进性能和样式的 25+ ASP 技巧(2)
改进性能和样式的 25+ ASP 技巧(3)
改进性能和样式的 25+ ASP 技巧(4)
表单递交内容检测脚本-这里只接受数字
如何使replace方法不区分大小写?
在 Web 页上使用条件数值格式
如何用asp把sqlserver数据转换为execl文件
用ADO STREAM做的无组件上传程序简单介绍
如何在主页中控制浏览权限

ASP.NET:访问Excel 电子表格


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 20 ::
收藏到网摘: n/a

  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 - didn't 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"/>