水晶报表的导出和打印 Push

简介:

<% @ 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

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,如需转载请自行联系原作者
相关文章
|
7月前
|
API
如何把自定义的函数,记录到你的Airtest报告里
如何把自定义的函数,记录到你的Airtest报告里
131 0
|
7月前
|
Windows
Lodop打印控件常用指令记录
Lodop打印控件常用指令记录
229 0
|
安全 数据安全/隐私保护
文档的保存和打印
3.8 文档的保存与打印 3.8.1 防止文档内容丢失 1. 自动恢复 Word提供自动恢复功能,可在很大程度上避免因为停电、机器死机等问题引发的文档丢失现象。在“文件”选项卡中的“选项”命令,在其中的“保存”选项卡中设置,默认10分钟,可以修改(1-120分钟)。 2. 自动备份文档副本 在编辑Word文档时,如果不小心保存了不需要的信息,或者原文档损坏,可以使用文档备份的副本避免损失。当然,这需要你事先在Word系统设置了“始终创建备份副本”功能,具体操作如下: 1单击“文件”选项卡,选择“选项”命令,打开对话框设置。 2选择此选项可在每次保存文档时创建一个文档的备份副本扩展名为 .wbk
|
图形学 C++
Qt实现Qchart的打印和打印预览的几种方法
Qt实现Qchart的打印和打印预览的几种方法
|
Windows
Qt日志库Log4Qt的使用,支持文件名/行号/函数名的log打印输出
Qt日志库Log4Qt的使用,支持文件名/行号/函数名的log打印输出
1512 0
|
索引
Blender软件导出的obj数据格式文件内容解读
版权声明:本文为博主原创文章,未经博主允许不得转载。更多学习资料请访问我爱科技论坛:www.52tech.tech https://blog.csdn.net/m0_37981569/article/details/79048521 【cube.
1947 0