用水晶报表导出DOC等文档
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;
namespace WebApplication1
{
/// <summary>
/// WebForm2 的摘要说明。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Data.SqlClient.SqlConnection sqlConn;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Web.UI.WebControls.Button btnGo;
protected CrystalDecisions.Web.CrystalReportViewer cryViewPubs;
private CryAuthors oRpt = null;
private CrystalDecisions.Shared.DiskFileDestinationOptions DiskOpts;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
//实例化架构
DSYoyo ds = new DSYoyo();
sqlDataAdapter1.Fill(ds);
//实例化报表
oRpt = new CryAuthors();
oRpt.SetDataSource(ds);
//设置报表viewer源
cryViewPubs.ReportSource = oRpt;
}
Web 窗体设计器生成的代码
private void btnGo_Click(object sender, System.EventArgs e)
{
fileCreat("doc");
}
public void fileCreat(string cFileType)
{
switch (cFileType)
{
case "pdf":
//pdf文件格式
DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
DiskOpts.DiskFileName = Server.MapPath("\WebApplication1\Output.pdf"); //将导出文件写入web目录,必须为WebApplication1文件夹设置asp.net的完全控制权限
oRpt.ExportOptions.DestinationOptions = DiskOpts;
oRpt.Export(); //文件导出
Session["fileTypeFlag"] = "1";
//LinkButton1_Click(this, new EventArgs()); //触发//LinkButton1_Click事件
break;
case "doc":
//Word文件格式
DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
DiskOpts.DiskFileName = Server.MapPath("\WebApplication1\Output.doc");
oRpt.ExportOptions.DestinationOptions = DiskOpts;
oRpt.Export();
Session["fileTypeFlag"] = "2";
//LinkButton1_Click(this, new EventArgs());
break;
case "excel":
//Excel文件格式
DiskOpts = new CrystalDecisions.Shared.DiskFileDestinationOptions();
oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
oRpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
DiskOpts.DiskFileName = Server.MapPath("\WebApplication1\Output.xls");
oRpt.ExportOptions.DestinationOptions = DiskOpts;
oRpt.Export();
Session["fileTypeFlag"] = "3";
//LinkButton1_Click(this, new EventArgs());
break;
}
}
}
}
posted on 2004-08-03 10:18 HelloSnoopy 阅读(631) 评论(0) 收藏 举报


浙公网安备 33010602011771号