登录社区
博客
直播
聚能聊
团队号
专家
小程序
NEW
更多
问答
下载
订阅
专题
商城
开发者社区
|
云生态
阿里云头条
博客
问答
聚能聊
直播
下载
论坛
云栖大会
开发者社区
登录社区
注册账号
水晶报表的导出和打印 Push
精简版
0
0
0
云栖社区
>
博客
>
正文
水晶报表的导出和打印 Push
老朱教授
2017-11-26 20:42:00
浏览1033
web
Server
asp
void
报表
Excel
展开阅读全文
<%
@ Register TagPrefix
=
"
cr
"
Namespace
=
"
CrystalDecisions.Web
"
Assembly
=
"
CrystalDecisions.Web, Version=10.0.3300.0, Culture=neutral, PublicKeyToken=692fbea5521e1304
"
%>
<%
@ Page language
=
"
c#
"
Codebehind
=
"
Main.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
CrystalPush.WebForm1
"
%>
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
title
>
WebForm1
</
title
>
<
meta
content
="Microsoft Visual Studio 7.0"
name
="GENERATOR"
>
<
meta
content
="C#"
name
="CODE_LANGUAGE"
>
<
meta
content
="JavaScript"
name
="vs_defaultClientScript"
>
<
meta
content
="http://schemas.microsoft.com/intellisense/ie5"
name
="vs_targetSchema"
>
</
HEAD
>
<
body
MS_POSITIONING
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
FONT
face
="宋体"
>
<
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
>
<
asp:Button
id
="btnPrint"
style
="Z-INDEX: 103; LEFT: 548px; POSITION: absolute; TOP: 15px"
runat
="server"
Width
="78px"
Text
="打印"
></
asp:Button
>
<
asp:Button
id
="btnExport"
style
="Z-INDEX: 102; LEFT: 434px; POSITION: absolute; TOP: 14px"
runat
="server"
Width
="78px"
Text
="导出"
></
asp:Button
>
<
asp:Label
id
="Label1"
style
="Z-INDEX: 104; LEFT: 26px; POSITION: absolute; TOP: 19px"
runat
="server"
>
请选择导出格式:
</
asp:Label
>
<
asp:DropDownList
id
="ddlFormat"
style
="Z-INDEX: 105; LEFT: 188px; POSITION: absolute; TOP: 16px"
runat
="server"
>
<
asp:ListItem
Value
="Rich Text (RTF)"
>
Rich Text (RTF)
</
asp:ListItem
>
<
asp:ListItem
Value
="Portable Document (PDF)"
>
Portable Document (PDF)
</
asp:ListItem
>
<
asp:ListItem
Value
="MS Word (DOC)"
>
MS Word (DOC)
</
asp:ListItem
>
<
asp:ListItem
Value
="MS Excel (XLS)"
>
MS Excel (XLS)
</
asp:ListItem
>
</
asp:DropDownList
></
FONT
></
form
>
</
body
>
</
HTML
>
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
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
System.IO;
using
System.Data.SqlClient;
using
UseCrystal.CrystalPush;
using
CrystalDecisions.CrystalReports.Engine;
using
CrystalDecisions.Shared;
namespace
CrystalPush
{
/**/
///
<summary>
///
WebForm1 的摘要说明。
///
</summary>
public
class
WebForm1 : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.Button btnExport;
protected
System.Web.UI.WebControls.Button btnPrint;
protected
CrystalDecisions.Web.CrystalReportViewer Crv;
protected
System.Web.UI.WebControls.Label Label1;
protected
System.Web.UI.WebControls.DropDownList ddlFormat;
myReport ReportDoc =
new
myReport();
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
string
strProvider = "Server=(local);DataBase=myDatabase;UID=sa;PWD=111";
SqlConnection MyConn =
new
SqlConnection(strProvider);
MyConn.Open();
string
strSel = "Select * from SaleOfCuntry";
SqlDataAdapter MyAdapter =
new
SqlDataAdapter(strSel,MyConn);
DataSet1 ds =
new
DataSet1();
MyAdapter.Fill(ds,"SaleOfCuntry");
ReportDoc.SetDataSource(ds);
Crv.ReportSource = ReportDoc;
}
Web Form Designer generated code
#region
Web Form Designer generated code
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.btnExport.Click +=
new
System.EventHandler(
this
.btnExport_Click);
this
.btnPrint.Click +=
new
System.EventHandler(
this
.btnPrint_Click);
this
.Load +=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
btnExport_Click(
object
sender, System.EventArgs e)
{
CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts =
new
CrystalDecisions.Shared.DiskFileDestinationOptions();
ReportDoc.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch
(ddlFormat.SelectedItem.Text)
{
case
"Rich Text (RTF)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.RichText;
//
DiskOpts.DiskFileName = "c:\\Output.rtf";
//
break
;
case
"Portable Document (PDF)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
//
DiskOpts.DiskFileName = "c:\\Output.pdf";
//
break
;
case
"MS Word (DOC)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
//
DiskOpts.DiskFileName = "c:\\Output.doc";
//
break
;
case
"MS Excel (XLS)":
ReportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
//
DiskOpts.DiskFileName = "c:\\Output.xls";
//
break
;
default
:
break
;
}
ReportDoc.ExportOptions.DestinationOptions = DiskOpts;
ReportDoc.Export();
}
private
void
btnPrint_Click(
object
sender, System.EventArgs e)
{
//
指定打印机名称,这里是网络工作站Gigi上的打印机Hp Jet 6
string
strPrinterName;
strPrinterName = @"Canon Bubble-Jet BJC-210SP";
//
设置打印页边距
PageMargins margins;
margins = ReportDoc.PrintOptions.PageMargins;
margins.bottomMargin = 250;
margins.leftMargin = 350;
margins.rightMargin = 350;
margins.topMargin = 450;
ReportDoc.PrintOptions.ApplyPageMargins(margins);
//
应用打印机名称
ReportDoc.PrintOptions.PrinterName = strPrinterName;
//
打印
//
打印报表。将 startPageN 和 endPageN
//
参数设置为 0 表示打印所有页。
ReportDoc.PrintToPrinter(1,
false
,0,0);
}
}
}
本文转自高海东博客园博客,原文链接:http://www.cnblogs.com/ghd258/archive/2005/10/25/261677.html,如需转载请自行联系原作者
本文首发在云栖社区,遵循云栖社区版权声明:本文内容由互联网用户自发贡献,版权归用户作者所有,云栖社区不为本文内容承担相关法律责任。云栖社区已在2020年6月升级到阿里云开发者社区。如果您发现有涉嫌抄袭的内容,请填写
侵权投诉表单
进行举报,一经查实,阿里云开发者社区将协助删除涉嫌侵权内容。
网友评论
登录
后评论
0
/500
评论
相关文章
基于DotNet构件技术的企业级敏捷软件开发平台 - AgileEAS.NET - 报表系统介绍
橘子红了呐
2017-11-16 17:08:00
浏览1043
ASP.NET中水晶报表的使用
ikingsmart
2008-09-14 02:10:00
浏览1161
水晶报表官方示例
杰克.陈
2015-12-23 19:36:00
浏览1005
水晶报表导出文件的格式设置
杰克.陈
2014-11-04 16:49:00
浏览724
报表,是件容易的事吗?
powertoolsteam
2014-08-26 14:04:00
浏览1027
c#水晶报表的进一步功能和使用
老朱教授
2017-10-17 22:18:00
浏览1185
C# WinForm开发系列 - Crystal Report
长征2号
2017-09-19 11:54:00
浏览1528
【水晶报表内功心法】--推拉之间
长空翱翔
2015-04-03 09:15:35
浏览778
我是如何搞定复杂水晶报表的(1)
余二五
2017-11-22 18:16:00
浏览1514
6-2 水晶报表技术(下)
余二五
2017-11-15 18:18:00
浏览1147
6-1 水晶报表技术(上)
余二五
2017-11-14 18:47:00
浏览941
水晶报表基础入门——7.晶报表导出数据技术1
余二五
2017-11-15 19:28:00
浏览1514
水晶报表基础入门——2.水晶报表命名空间下包含的类2
余二五
2017-11-16 19:31:00
浏览816
水晶报表基础入门——2.水晶报表命名空间下包含的类
余二五
2017-11-14 19:32:00
浏览773
水晶报表技术(6)——如何在.Net Web应用中使用水晶报表1
余二五
2017-11-15 19:38:00
浏览985
水晶报表制作实例
极简吧
2015-04-22 15:23:38
浏览1072
折腾 VS2008 + ReportViewer + CrystalReports + PrintControl.cab 实现水晶报表本地打印
技术小阿哥
2017-11-28 09:37:00
浏览1142
DIFramework.NET ━ Web中打印的各种方案参考-欢迎补充
科技小先锋
2017-11-24 22:55:00
浏览1084
Asp.net2.0水晶报表的一些示例源码
技术小阿哥
2017-11-26 16:22:00
浏览882
RDIFramework.NET ━ Web中打印的各种方案参考-欢迎补充
rdiframework
2015-01-09 09:41:15
浏览738
下拉加载更多
作者介绍
老朱教授
+ 关注
3569
文章数
33
粉丝数
0
关注的人
下一篇
【云栖号直播】本周重磅:2020阿里云弹性计算年度发布会
云栖号资讯小编
27638人浏览
本文目录
网友评论