📄 readexcel.aspx.cs
字号:
//-----------------------------------------------------------------------
//
// WebExpert.NET 1.0
//
// (c) 2003, www.AspCool.com. All rights reserved.
// ASP酷技术网 版权所有
//
// 该源码下载自:http://www.51aspx.com
// 邮箱:tim@aspcool.com
//
// 版权声明:本程序仅供学习使用,你也可以修改后在网站上使用,但使用时必
// 须保留ASP酷技术网(www.AspCool.com)的版权信息和链接。本程序随《ASP.NET
// 网站建设专家》一书赠送,未经作者同意,不得随意修改、传播。
//
// 描述:
// 此文件包含下面的类:
// ReadExcel
//
// 作者: 王保健
// 时间: 2005-01-15
//
//------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
namespace AspCool.WebExpert.Excel
{
/// <summary>
/// ReadExcel 的摘要说明。
/// </summary>
public class ReadExcel : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
// Excel文件连接字符串
string connString =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\wwwroot\WebExpert\Excel\book1.xls;Extended Properties=Excel 8.0";
// 定义OleDb连接
OleDbConnection conn = new OleDbConnection(connString);
// 定义OleDb命令
OleDbCommand comm = new OleDbCommand("SELECT * FROM [Sheet1$]",conn);
// 定义OleDbDataAdapter
OleDbDataAdapter adapter = new OleDbDataAdapter(comm);
DataSet ds = new DataSet();
// 向DataSet中填充数据
adapter.Fill(ds);
//设置数据源
DataGrid1.DataSource = ds;
//数据绑定
DataGrid1.DataBind();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -