水晶报表的导出和打印 Push

  1. 云栖社区>
  2. 博客>
  3. 正文

水晶报表的导出和打印 Push

老朱教授 2017-11-26 20:42:00 浏览1033
展开阅读全文

ExpandedBlockStart.gifContractedBlock.gif<%dot.gif@ Register TagPrefix="cr" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>
ExpandedBlockStart.gifContractedBlock.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.gifusing System;
None.gifusing System.Collections;
None.gifusing System.ComponentModel;
None.gifusing System.Data;
None.gifusing System.Drawing;
None.gifusing System.Web;
None.gifusing System.Web.SessionState;
None.gifusing System.Web.UI;
None.gifusing System.Web.UI.WebControls;
None.gifusing System.Web.UI.HtmlControls;
None.gifusing System.IO;
None.gifusing System.Data.SqlClient;
None.gifusing UseCrystal.CrystalPush;
None.gifusing CrystalDecisions.CrystalReports.Engine;
None.gifusing CrystalDecisions.Shared;
None.gifnamespace CrystalPush
ExpandedBlockStart.gifContractedBlock.gifdot.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/500
评论
老朱教授
+ 关注