博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
水晶报表的导出和打印 Push
阅读量:6086 次
发布时间:2019-06-20

本文共 5649 字,大约阅读时间需要 18 分钟。

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.gif
ContractedSubBlock.gif
/**/
///
<summary>
InBlock.gif
///
WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif
///
</summary>
InBlock.gif
public
class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.gif{
InBlock.gif
protected System.Web.UI.WebControls.Button btnExport;
InBlock.gif
protected System.Web.UI.WebControls.Button btnPrint;
InBlock.gif
protected CrystalDecisions.Web.CrystalReportViewer Crv;
InBlock.gif
protected System.Web.UI.WebControls.Label Label1;
InBlock.gif
protected System.Web.UI.WebControls.DropDownList ddlFormat;
InBlock.gif myReport ReportDoc =
new myReport();
InBlock.gif
private
void Page_Load(
object sender, System.EventArgs e)
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.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.gif
string 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.gif
ExpandedSubBlockStart.gif
Web Form Designer generated code
#region Web Form Designer generated code
InBlock.gif
override
protected
void OnInit(EventArgs e)
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.gif{
InBlock.gif
//
InBlock.gif
//
CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif
//
InBlock.gif
InitializeComponent();
InBlock.gif
base.OnInit(e);
ExpandedSubBlockEnd.gif }
InBlock.gif
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
/**/
///
<summary>
InBlock.gif
///
设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif
///
此方法的内容。
ExpandedSubBlockEnd.gif
///
</summary>
InBlock.gif
private
void InitializeComponent()
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.gif{
InBlock.gif
this.btnExport.Click +=
new System.EventHandler(
this.btnExport_Click);
InBlock.gif
this.btnPrint.Click +=
new System.EventHandler(
this.btnPrint_Click);
InBlock.gif
this.Load +=
new System.EventHandler(
this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif }
ExpandedSubBlockEnd.gif
#endregion
InBlock.gif
InBlock.gif
private
void btnExport_Click(
object sender, System.EventArgs e)
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.gif{
InBlock.gif CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts =
new CrystalDecisions.Shared.DiskFileDestinationOptions();
InBlock.gif ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
InBlock.gif
switch (ddlFormat.SelectedItem.Text)
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.gif{
InBlock.gif
case "Rich Text (RTF)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;
//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.rtf";
//
InBlock.gif
break;
InBlock.gif
case "Portable Document (PDF)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.pdf";
//
InBlock.gif
break;
InBlock.gif
case "MS Word (DOC)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.doc";
//
InBlock.gif
break;
InBlock.gif
case "MS Excel (XLS)":
InBlock.gif  ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
//
InBlock.gif
  DiskOpts.DiskFileName = "c:\\Output.xls";
//
InBlock.gif
break;
InBlock.gif
default:
InBlock.gif
break;
ExpandedSubBlockEnd.gif }
InBlock.gif ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
InBlock.gif  ReportDoc.Export();
ExpandedSubBlockEnd.gif }
InBlock.gif
InBlock.gif
private
void btnPrint_Click(
object sender, System.EventArgs e)
ExpandedSubBlockStart.gif
ContractedSubBlock.gif
dot.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,如需转载请自行联系原作者
你可能感兴趣的文章
CodeForces 580B Kefa and Company
查看>>
开发规范浅谈
查看>>
Spark Streaming揭秘 Day29 深入理解Spark2.x中的Structured Streaming
查看>>
鼠标增强软件StrokeIt使用方法
查看>>
本地连接linux虚拟机的方法
查看>>
某公司面试java试题之【二】,看看吧,说不定就是你将要做的题
查看>>
BABOK - 企业分析(Enterprise Analysis)概要
查看>>
Linux 配置vnc,开启linux远程桌面
查看>>
NLog文章系列——如何优化日志性能
查看>>
Hadoop安装测试简单记录
查看>>
CentOS6.4关闭触控板
查看>>
ThreadPoolExecutor线程池运行机制分析-线程复用原理
查看>>
React Native 极光推送填坑(ios)
查看>>
Terratest:一个用于自动化基础设施测试的开源Go库
查看>>
修改Windows远程终端默认端口,让服务器更安全
查看>>
扩展器必须,SAS 2.0未必(SAS挺进中端存储系统之三)
查看>>
Eclipse遇到Initializing Java Tooling解决办法
查看>>
while((ch = getchar()) != '\n')
查看>>
好程序员web前端分享JS检查浏览器类型和版本
查看>>
Oracle DG 逻辑Standby数据同步性能优化
查看>>