crystalexport.aspx.cs
来自「ASP.NET的一些开发实例,有论坛管理系统等」· CS 代码 · 共 92 行
CS
92 行
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;
namespace CrystalEg
{
/// <summary>
/// CrystalExport 的摘要说明。
/// </summary>
public class CrystalExport : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList ddlType;
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Button Button1;
protected CrystalReport2 cr;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
BindReport();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void BindReport()
{
//指定连接数据库字符串
string strConn = "Server=LIUFPAD;DataBase=Northwind;UID=sa;PWD=";
//实例化报表文件
cr = new CrystalReport2();
//实例化数据集
Dataset1 ds = new Dataset1();
//查询语句
string sql = "Select * from Customers";
ReportsService.FillDataSet(ds,"Customers",sql,strConn);
//报表文件绑定数据集
cr.SetDataSource(ds);
//指定CrystalReportViewer1控件的ReportSource属性
this.CrystalReportViewer1.ReportSource = cr;
}
private void Button1_Click(object sender, System.EventArgs e)
{
CrystalDecisions.Shared.ExportFormatType et=CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
switch(this.ddlType.SelectedItem.Value)
{
case "0":
et=CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
break;
case "1":
et=CrystalDecisions.Shared.ExportFormatType.Excel;
break;
case "2":
et=CrystalDecisions.Shared.ExportFormatType.WordForWindows;
break;
}
bool bSave=true;
//根据时间为临时存储报表的文件命名
string Fname = "c:\\" + DateTime.Now.ToString("yyyyMMddhhmmss");
CrystalEg.ReportsService.Export(this,cr,et,CrystalDecisions.Shared.ExportDestinationType.DiskFile,bSave,Fname);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?