用CRYSTAL在客户端打印没做过! 不过以前自己写过一个ACTIVE X 控件在客户端输出数据到EXCEL文件!大概的过程是这样的: 1、客户端下载安装ACTIVE X 控件; 2、控件调用服务器端的WEB SERVICE获取要输出的数据和EXCEL格式设定参数; 3、控件在客户端调用EXCEL,输出数据至一个EXCEL文件!不清楚CRYSTAL 10在客户端打印的实现方式,但我想至少前两步应该是相似的: 客户端一定要安装ACTIVE X控件和设定这个控件的数据源!
问题终于解决了,贴出源代码<%@ Register TagPrefix="cr" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %> <%@ Register TagPrefix="ce" Namespace="CrystalDecisions.Enterprise.WebControls" Assembly="CrystalDecisions.Enterprise.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %> <%@ Page language="c#" Codebehind="Customers.aspx.cs" AutoEventWireup="false" Inherits="Angushine.Web.Report.Customers" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Customers</title> <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" Content="C#"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <link type="text/css" rel="stylesheet" href="../Css.css"> </HEAD> <body> <form id="Form1" method="post" runat="server"> <FONT face="宋体"></FONT> <cr:CrystalReportViewer id="CrystalReportViewer1" runat="server" Height="50px" Width="350px" AutoDataBind="true" HasExportButton="False" HasGotoPageButton="False" HasSearchButton="False" HasToggleGroupTreeButton="False" HasZoomFactorList="False"></cr:CrystalReportViewer> <BR> <asp:Button id="btnCustomers" runat="server" Text="Customers"></asp:Button> <asp:Button id="btnEmployees" runat="server" Text="Employees"></asp:Button> <asp:Button id="btnProducts" runat="server" Text="Products"></asp:Button><BR> </form> </body> </HTML>using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Data.SqlClient; 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 CrystalDecisions.Shared ; //TableLogOnInfo类 using CrystalDecisions.CrystalReports.Engine ; //ReportDocument类namespace Angushine.Web.Report { /// <summary> /// Customers 的摘要说明。 /// </summary> public class Customers : System.Web.UI.Page { protected System.Web.UI.WebControls.Button btnEmployees; protected System.Web.UI.WebControls.Button btnProducts; protected System.Web.UI.WebControls.Button btnCustomers; protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; private static ReportDocument oRpt;
private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { } else { //If the report has been previewed once, the ReportSource needs to be //set on each postback. When the Preview Report button is first clicked, //it loads the report, binds it to the viewer, and puts the ReportDocument //object into a Session varable. This code pulls that ReportDocument object //from Session and reassigns the viewer's ReportSource, for each postback. if (oRpt != null) { CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX; CrystalReportViewer1.ReportSource = oRpt; } } } #region Web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); }
/// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.btnCustomers.Click += new System.EventHandler(this.btnCustomers_Click); this.btnEmployees.Click += new System.EventHandler(this.btnEmployees_Click); this.btnProducts.Click += new System.EventHandler(this.btnProducts_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void btnCustomers_Click(object sender, System.EventArgs e) { /* * pull模式,建立rpt文件,以及web页面,其中页面控件不需指定数据源. * */ TableLogOnInfo logOnInfo = new TableLogOnInfo (); oRpt = new ReportDocument(); string path = this.Server.MapPath("CrReports/Customers.rpt"); oRpt.Load (path);
/* MS Server 2000数据库,其他作相应的改动 */ logOnInfo.ConnectionInfo.ServerName = "localhost"; logOnInfo.ConnectionInfo.UserID = "sa"; logOnInfo.ConnectionInfo.Password = "sa"; oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
如果出现不能打印的情况,请检查一下
一、是否已经安装打印机。
二、编写的程序是否有问题,如:是否再form_load里用if (!this.IsPostBack)将读取数据部分屏蔽了,因为在打印时需要从新到获取数据的。
不过以前自己写过一个ACTIVE X 控件在客户端输出数据到EXCEL文件!大概的过程是这样的:
1、客户端下载安装ACTIVE X 控件;
2、控件调用服务器端的WEB SERVICE获取要输出的数据和EXCEL格式设定参数;
3、控件在客户端调用EXCEL,输出数据至一个EXCEL文件!不清楚CRYSTAL 10在客户端打印的实现方式,但我想至少前两步应该是相似的:
客户端一定要安装ACTIVE X控件和设定这个控件的数据源!
<%@ Register TagPrefix="ce" Namespace="CrystalDecisions.Enterprise.WebControls" Assembly="CrystalDecisions.Enterprise.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
<%@ Page language="c#" Codebehind="Customers.aspx.cs" AutoEventWireup="false" Inherits="Angushine.Web.Report.Customers" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Customers</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<link type="text/css" rel="stylesheet" href="../Css.css">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋体"></FONT>
<cr:CrystalReportViewer id="CrystalReportViewer1" runat="server" Height="50px" Width="350px" AutoDataBind="true"
HasExportButton="False" HasGotoPageButton="False" HasSearchButton="False" HasToggleGroupTreeButton="False"
HasZoomFactorList="False"></cr:CrystalReportViewer>
<BR>
<asp:Button id="btnCustomers" runat="server" Text="Customers"></asp:Button>
<asp:Button id="btnEmployees" runat="server" Text="Employees"></asp:Button>
<asp:Button id="btnProducts" runat="server" Text="Products"></asp:Button><BR>
</form>
</body>
</HTML>using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 CrystalDecisions.Shared ; //TableLogOnInfo类
using CrystalDecisions.CrystalReports.Engine ; //ReportDocument类namespace Angushine.Web.Report
{
/// <summary>
/// Customers 的摘要说明。
/// </summary>
public class Customers : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button btnEmployees;
protected System.Web.UI.WebControls.Button btnProducts;
protected System.Web.UI.WebControls.Button btnCustomers;
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1; private static ReportDocument oRpt;
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{ }
else
{
//If the report has been previewed once, the ReportSource needs to be
//set on each postback. When the Preview Report button is first clicked,
//it loads the report, binds it to the viewer, and puts the ReportDocument
//object into a Session varable. This code pulls that ReportDocument object
//from Session and reassigns the viewer's ReportSource, for each postback.
if (oRpt != null)
{
CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.ActiveX;
CrystalReportViewer1.ReportSource = oRpt;
}
}
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnCustomers.Click += new System.EventHandler(this.btnCustomers_Click);
this.btnEmployees.Click += new System.EventHandler(this.btnEmployees_Click);
this.btnProducts.Click += new System.EventHandler(this.btnProducts_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btnCustomers_Click(object sender, System.EventArgs e)
{
/*
* pull模式,建立rpt文件,以及web页面,其中页面控件不需指定数据源.
* */
TableLogOnInfo logOnInfo = new TableLogOnInfo ();
oRpt = new ReportDocument(); string path = this.Server.MapPath("CrReports/Customers.rpt");
oRpt.Load (path);
/* MS Server 2000数据库,其他作相应的改动 */
logOnInfo.ConnectionInfo.ServerName = "localhost";
logOnInfo.ConnectionInfo.UserID = "sa";
logOnInfo.ConnectionInfo.Password = "sa"; oRpt.Database.Tables[0].ApplyLogOnInfo(logOnInfo);
CrystalReportViewer1.ReportSource = oRpt; //建立.rpt文件与CryStalReportviewer文件之间的连接
//The ReportDocument object will need to placed into Session so that
//on each postback, the viewer's ReportSource can be set to this instance
Session.Add("REPORT", oRpt);
} private void btnEmployees_Click(object sender, System.EventArgs e)
{
string strDB = System.Configuration.ConfigurationSettings.AppSettings["strDB"];
SqlConnection conn = new SqlConnection(strDB);
SqlDataAdapter da = new SqlDataAdapter("Select * from Employees",conn);
CrReports.DataSet1 ds = new Angushine.Web.Report.CrReports.DataSet1();
CrReports.Employees myrpt = new Angushine.Web.Report.CrReports.Employees();
da.Fill(ds,"t");
myrpt.SetDataSource(ds.Tables["t"]);
myrpt.Refresh();
this.CrystalReportViewer1.ReportSource = myrpt;
//myrpt.PrintToPrinter(1,true,1,1);
this.CrystalReportViewer1.DataBind();
} private void btnProducts_Click(object sender, System.EventArgs e)
{
// 数据源是连接Access
oRpt = new ReportDocument();
string path = this.Server.MapPath("CrReports/Customer.rpt");
oRpt.Load (path);
CrystalReportViewer1.ReportSource = oRpt;
} private void ReportPrint1_SubmitClicked(object sender, System.EventArgs e)
{
//oRpt.PrintToPrinter(1, false,0,0);
} private void CrystalReportViewer1_Init(object sender, System.EventArgs e)
{
}
}
}
贴出代码,大家一起共享