水晶报表导出为pdf, word , excel 格式(已经测试过,实现了该功能)
来源:互联网 发布:java 获取get请求参数 编辑:程序博客网 时间:2024/04/29 06:04
using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
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 CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;
using Ghy.Funds.FundsClassLibrary;
using System.Data.SqlClient;
namespace WebAppTest
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.Button Btn_Export;
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.Button btn_Export2;
ReportDocument reportDoc=new ReportDocument();
//页面加载
//SqlConnection myconn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectString"]);
//SqlConnection myconn1 = new SqlConnection(ConfigurationSettings.AppSettings["ConnectString"]);
//读取web.config配置文件中的数据库连接字符串,并连接到指定的数据库
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!Page.IsPostBack)
{
//测试的时候用绑定
reportDataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btn_Export2.Click += new System.EventHandler(this.btn_Export2_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
//绑定数据源
private void reportDataBind()
{
SqlConnection myConn = new SqlConnection("server = 11.101.10.8; database =eProcessDB; uid = sa; pwd =admin@sa ");
string sql = "SELECT FUNDS_RPT_HQ.VKBUR, FUNDS_RPT_HQ.VKBUR_NAME, FUNDS_RPT_HQ.FORM_DATE, FUNDS_RPT_HQ.AMT_BEG, FUNDS_RPT_HQ.INGDS, FUNDS_RPT_HQ.INOTH, FUNDS_RPT_HQ.PAYHQ, FUNDS_RPT_HQ.PAYOTH, FUNDS_RPT_HQ.AMT_END, FUNDS_RPT_HQ.TOT_INGDS, FUNDS_RPT_HQ.TOT_PAYHQ, FUNDS_RPT_HQ.FEE_END FROM FUNDS_RPT_HQ WHERE FUNDS_RPT_HQ.FORM_DATE ='2007-05-09' " ;
myConn.Open();
SqlDataAdapter myComm = new SqlDataAdapter(sql, myConn);
DataSet dset1 = new DataSet();
myComm.Fill(dset1,"FUNDS_RPT_HQ");
myConn.Close();
string ls_rptPathName;
ls_rptPathName = Server.MapPath(".")+"//Funds_Rpt_HQ.rpt";
reportDoc.Load(ls_rptPathName);
reportDoc.SetDataSource(dset1);
CrystalReportViewer1.ReportSource = reportDoc;
CrystalReportViewer1.DisplayGroupTree = false; //树视图是可见还是隐藏左边的空白显示的比较多的处理方法
}
private void btn_Export2_Click(object sender, System.EventArgs e)
{
reportDataBind();
string contenttype = "";
string ls_FileType;
ls_FileType = DropDownList2.SelectedValue;
string ExportPath;
string Fname;
ExportPath = Request.PhysicalApplicationPath + "Exported/";
if ( !Directory.Exists(ExportPath))
{
System.IO.Directory.CreateDirectory(Request.PhysicalApplicationPath + "Exported/");
}
Fname = "Funds_rpt_HQ";
CrystalDecisions.Shared.DiskFileDestinationOptions opts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
//导出为磁盘文件
CrystalDecisions.Shared.ExportOptions myExportOptions = reportDoc.ExportOptions;
myExportOptions.DestinationOptions = opts;
myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch(DropDownList2.SelectedItem.Value)
{
case "PDF":
contenttype = "application/pdf";
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
break;
case "DOC":
Response.ContentType = "application/ms-excel";
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
break;
case "XLS":
contenttype = "application/vnd.ms-excel";
this.EnableViewState = false;
myExportOptions.ExportFormatType =CrystalDecisions.Shared.ExportFormatType.Excel;
break;
}
Fname = Fname +"." + DropDownList2.SelectedItem.Value;
opts.DiskFileName = ExportPath + Fname ;
//导出操作
reportDoc.Export();
CommonCode.JavaShowWindow("导出文件成功!");
}
}
}
- 水晶报表导出为pdf, word , excel 格式(已经测试过,实现了该功能)
- 水晶报表导出为word,excel和pdf格式
- 水晶报表导出为word,excel和pdf格式
- 水晶报表导出PDF or Excel
- 水晶报表导出PDF or Excel
- 水晶报表导出为word遇到问题。。
- 报表导出到word或者excel的功能实现
- Ireport 报表导出 Poi + ireport 导出pdf, word ,excel ,html 格式
- JAVA如何把word,excel,ppt转成PDF,已经过测试成功。
- 为什么JSP导出为excel,word后丢失了格式?
- 关于水晶报表导出到PDF格式的一个注意事项
- ireport导出各种格式(pdf,excel,word,html,print)
- ireport导出各种格式(pdf,excel,word,html,print)
- 报表导出为CVS,pdf格式文件格式
- 水晶报表导出pdf功能(完整的代码C#版)
- Firefox导出Excel报表为Html格式
- 限制水晶报表导出格式
- 水晶报表导出到Excel
- spring配置文件- 数据库
- OneNote2007简体中文便携版
- 解决ubuntu9.10更新后不能无线上网
- 手机网游开发基础知识之Wap协议
- 水晶报表导出pdf功能(完整的代码C#版)
- 水晶报表导出为pdf, word , excel 格式(已经测试过,实现了该功能)
- 软件架构设计
- 受美国国会影响 谷歌4月10日退出中国
- 性能标准两腿走:IE9平台预览版初步体验————来源:驱动之家
- 在数据库中保存会话session
- C#-DataGridView导入Excel
- HyperThreading?
- 在DirectX3D程序中加载3DMAX的模型(后缀为.X的文件)
- VB MSHFLEXGRID MSHFLEXGRID 绑定 CHECKBOX