//导出报表
protected void btnExport_Click(object sender, EventArgs e)
{
string contentype = "";
string ls_FileType;
//获取下拉框值
ls_FileType = ddlFormat.SelectedValue;
string ExportPath;
string Fname;
ExportPath = Request.PhysicalApplicationPath + "Exported/";
if (!Directory.Exists(ExportPath))
{
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 (ddlFormat.SelectedItem.Value)
{
case "PDF":
contentype = "application/pdf";
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
break;
case "DOC":
contentype = "application/ms-excel";
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
break;
case "XLS":
contentype = "application/vnd.ms-excel";
this.EnableViewState = false;
myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.Excel;
break;
}
Fname = Fname + ddlFormat.SelectedItem.Value;
opts.DiskFileName = ExportPath + Fname;
//导出操作
try
{
ReportDoc.Export();
Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", @"<script>alert('导出成功!');</script>");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
水晶报表的导出
最新推荐文章于 2019-05-17 08:31:22 发布