开发者社区> 老朱教授> 正文

水晶报表的导出和打印 Push

简介:
+关注继续查看

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,如需转载请自行联系原作者

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
WIN10文件名排序错误的案例截图
WIN10文件名排序错误的案例截图
11 0
Unity用GUI绘制Debug/print窗口/控制台-打包后测试
Unity游戏视窗控制台输出 本文提供全流程,中文翻译。 Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 —— 高分辨率用户请根据需求调整网页缩放比例) Chinar —— 心...
1853 0
Blender软件导出的obj数据格式文件内容解读
版权声明:本文为博主原创文章,未经博主允许不得转载。更多学习资料请访问我爱科技论坛:www.52tech.tech https://blog.csdn.net/m0_37981569/article/details/79048521 【cube.
1632 0
+关注
老朱教授
文章
问答
视频
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载