今天要写一ECN项目的时候需要用到导出的功能:
在网络上找了一些资料。结合自己的情况修改调试一下了 先看看效果吧
写到页面上了。再看看是否写到指定目录了?
OK 成功了 一下是代码
----------------------------------------------------------以下为报表加载
.....
stringreportPath=Server.MapPath("..//Reports//project.rpt");
//doc.Load(@"C:/test/1.rpt");
doc.Load(reportPath);
doc.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource=doc;
CrystalReportViewer1.DataBind();
----------------------------------------------------------实现生成指定格式的文件到指定目录
stringfiletype="";
filetype=ddl_FileFormat.SelectedValue;
stringcontenttype="";
//stringmyfilename=Request.MapPath(".//")+Session.SessionID+"."+filetype;//目录地址注意反义字符
stringmyfilename="C://test//"+Session.SessionID+"."+filetype;
CrystalDecisions.Shared.DiskFileDestinationOptionsmydiskoptions=newCrystalDecisions.Shared.DiskFileDestinationOptions();
mydiskoptions.DiskFileName=myfilename;
CrystalDecisions.Shared.ExportOptionsmyExportOptions=newExportOptions();//oCR.ExportOptions;
myExportOptions.DestinationOptions=mydiskoptions;
myExportOptions.ExportDestinationType=CrystalDecisions.Shared.ExportDestinationType.DiskFile;
switch(ddl_FileFormat.SelectedItem.Value)//类别
{
case"pdf":
contenttype="application/pdf";
myExportOptions.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
break;
case"doc":
contenttype="application/msword";
myExportOptions.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.WordForWindows;
break;
case"XLS":
contenttype="application/vnd.ms-excel";
myExportOptions.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.Excel;
break;
case"RTF":
contenttype="application/rtf";
myExportOptions.ExportFormatType=CrystalDecisions.Shared.ExportFormatType.RichText;
break;
}
doc.Export(myExportOptions);//输出报表到服务器端的制定路径
Response.ClearContent();//清空页面
Response.ClearHeaders();
Response.ContentType=contenttype;
Response.WriteFile(myfilename);//直接写入页面,页面平铺可实现在线阅读功能
Response.Flush();
Response.Close();
//水晶报表中的电子签名 后续再讲咯