水晶报表的导出和打印 Push

ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Register TagPrefix="cr" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Page language="c#" Codebehind="Main.aspx.cs" AutoEventWireup="false" Inherits="CrystalPush.WebForm1" %>
None.gif <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif < HTML >
None.gif < HEAD >
None.gif < title >WebForm1 </ title >
None.gif < meta content ="Microsoft Visual Studio 7.0" name ="GENERATOR" >
None.gif < meta content ="C#" name ="CODE_LANGUAGE" >
None.gif < meta content ="JavaScript" name ="vs_defaultClientScript" >
None.gif < meta content ="http://schemas.microsoft.com/intellisense/ie5" name ="vs_targetSchema" >
None.gif </ HEAD >
None.gif < body MS_POSITIONING ="GridLayout" >
None.gif < form id ="Form1" method ="post" runat ="server" >
None.gif < FONT face ="宋体" >
None.gif < CR:CRYSTALREPORTVIEWER id ="Crv" style ="Z-INDEX: 101; LEFT: 16px; POSITION: absolute; TOP: 54px" runat ="server" Height ="50px" Width ="350px" HasZoomFactorList ="False" HasDrillUpButton ="False" HasGotoPageButton ="False" HasPageNavigationButtons ="False" HasSearchButton ="False" ></ CR:CRYSTALREPORTVIEWER >
None.gif < asp:Button id ="btnPrint" style ="Z-INDEX: 103; LEFT: 548px; POSITION: absolute; TOP: 15px" runat ="server" Width ="78px" Text ="打印" ></ asp:Button >
None.gif < asp:Button id ="btnExport" style ="Z-INDEX: 102; LEFT: 434px; POSITION: absolute; TOP: 14px" runat ="server" Width ="78px" Text ="导出" ></ asp:Button >
None.gif < asp:Label id ="Label1" style ="Z-INDEX: 104; LEFT: 26px; POSITION: absolute; TOP: 19px" runat ="server" >请选择导出格式: </ asp:Label >
None.gif < asp:DropDownList id ="ddlFormat" style ="Z-INDEX: 105; LEFT: 188px; POSITION: absolute; TOP: 16px" runat ="server" >
None.gif < asp:ListItem Value ="Rich Text (RTF)" >Rich Text (RTF) </ asp:ListItem >
None.gif < asp:ListItem Value ="Portable Document (PDF)" >Portable Document (PDF) </ asp:ListItem >
None.gif < asp:ListItem Value ="MS Word (DOC)" >MS Word (DOC) </ asp:ListItem >
None.gif < asp:ListItem Value ="MS Excel (XLS)" >MS Excel (XLS) </ asp:ListItem >
None.gif </ asp:DropDownList ></ FONT ></ form >
None.gif </ body >
None.gif </ HTML >

None.gif using System;
None.gif using System.Collections;
None.gif using System.ComponentModel;
None.gif using System.Data;
None.gif using System.Drawing;
None.gif using System.Web;
None.gif using System.Web.SessionState;
None.gif using System.Web.UI;
None.gif using System.Web.UI.WebControls;
None.gif using System.Web.UI.HtmlControls;
None.gif using System.IO;
None.gif using System.Data.SqlClient;
None.gif using UseCrystal.CrystalPush;
None.gif using CrystalDecisions.CrystalReports.Engine;
None.gif using CrystalDecisions.Shared;
None.gif namespace CrystalPush
ExpandedBlockStart.gif ContractedBlock.gif dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif/**//// <summary>
InBlock.gif
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif
/// </summary>
InBlock.gifpublic class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifprotected System.Web.UI.WebControls.Button btnExport;
InBlock.gifprotected System.Web.UI.WebControls.Button btnPrint;
InBlock.gifprotected CrystalDecisions.Web.CrystalReportViewer Crv;
InBlock.gifprotected System.Web.UI.WebControls.Label Label1;
InBlock.gifprotected System.Web.UI.WebControls.DropDownList ddlFormat;
InBlock.gif myReport ReportDoc = new myReport();
InBlock.gifprivate void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif// 在此处放置用户代码以初始化页面
InBlock.gif
string strProvider = "Server=(local);DataBase=myDatabase;UID=sa;PWD=111";
InBlock.gif SqlConnection MyConn = new SqlConnection(strProvider);
InBlock.gif MyConn.Open();
InBlock.gifstring strSel = "Select * from SaleOfCuntry";
InBlock.gif SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);
InBlock.gif DataSet1 ds = new DataSet1();
InBlock.gif MyAdapter.Fill(ds,"SaleOfCuntry");
InBlock.gif ReportDoc.SetDataSource(ds);
InBlock.gif Crv.ReportSource = ReportDoc;
InBlock.gif
ExpandedSubBlockEnd.gif }
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gifWeb Form Designer generated code#region Web Form Designer generated code
InBlock.gifoverride protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif//
InBlock.gif
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif
//
InBlock.gif
InitializeComponent();
InBlock.gifbase.OnInit(e);
ExpandedSubBlockEnd.gif }
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif/**//// <summary>
InBlock.gif
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif
/// 此方法的内容。
ExpandedSubBlockEnd.gif
/// </summary>
InBlock.gifprivate void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifthis.btnExport.Click += new System.EventHandler(this.btnExport_Click);
InBlock.gifthis.btnPrint.Click += new System.EventHandler(this.btnPrint_Click);
InBlock.gifthis.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif }
ExpandedSubBlockEnd.gif#endregion
InBlock.gif
InBlock.gifprivate void btnExport_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
InBlock.gif ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
InBlock.gifswitch (ddlFormat.SelectedItem.Text)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gifcase "Rich Text (RTF)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.rtf";//
InBlock.gif
break;
InBlock.gifcase "Portable Document (PDF)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.pdf";//
InBlock.gif
break;
InBlock.gifcase "MS Word (DOC)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.doc";//
InBlock.gif
break;
InBlock.gifcase "MS Excel (XLS)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.xls";//
InBlock.gif
break;
InBlock.gifdefault:
InBlock.gifbreak;
ExpandedSubBlockEnd.gif }
InBlock.gif ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
InBlock.gif  ReportDoc.Export();
ExpandedSubBlockEnd.gif }
InBlock.gif
InBlock.gifprivate void btnPrint_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
InBlock.gif// 指定打印机名称,这里是网络工作站Gigi上的打印机Hp Jet 6
InBlock.gif
string strPrinterName;
InBlock.gif strPrinterName = @"Canon Bubble-Jet BJC-210SP";
InBlock.gif// 设置打印页边距
InBlock.gif
PageMargins margins;
InBlock.gif margins = ReportDoc.PrintOptions.PageMargins;
InBlock.gif margins.bottomMargin = 250;
InBlock.gif margins.leftMargin = 350;
InBlock.gif margins.rightMargin = 350;
InBlock.gif margins.topMargin = 450;
InBlock.gif ReportDoc.PrintOptions.ApplyPageMargins(margins);
InBlock.gif//应用打印机名称
InBlock.gif
ReportDoc.PrintOptions.PrinterName = strPrinterName;
InBlock.gif// 打印 // 打印报表。将 startPageN 和 endPageN
InBlock.gif
// 参数设置为 0 表示打印所有页。
InBlock.gif
ReportDoc.PrintToPrinter(1, false,0,0);
InBlock.gif
ExpandedSubBlockEnd.gif }
ExpandedSubBlockEnd.gif }
ExpandedBlockEnd.gif}
None.gif



本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/25/261677.html,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值