在VS2008中,利用VS2008自带的CrystalReport做报表开发。前台页面点击一个button,页面会在CrystalReportViewer控件显示报表内容。打印直接点击CrystalReportViewer控件的打印button。此时CrystalReportViewer控件会将报表默认导出到pdf中。现在我想在页面不用CrystalReportViewer控件显示,而是直接点击一个button,直接将报表内容显示在pdf中,请问大家如何实现该功能?
调试欢乐多
嗯,就那么理解。就是打击button后直接将报表内容显示在pdf文件中~~
----
y要么显示在VIEW中,要么直接就打印了,用PRINTTOPRINT方法
//导出为磁盘文件
CrystalDecisions.Shared.ExportOptions myExportOptions =reportDoc.ExportOptions;
myExportOptions.DestinationOptions = opts;
myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
//导出为pdf格式
reportDoc.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
//目的路径
opts.DiskFileName =this.saveFileDialog1.FileName;
//导出操作
reportDoc.Export();
string fileFullName = string.Empty;
try
{
CrystalDecisions.Shared.DiskFileDestinationOptions crFileOptions = new CrystalDecisions.Shared.DiskFileDestinationOptions();
fileName = Guid.NewGuid().ToString().Substring(0, 8) + ".pdf";
fileFullName = HttpContext.Current.Server.MapPath("~/Report/") + fileName;
crFileOptions.DiskFileName = fileFullName; RptDoc.ExportOptions.DestinationOptions = crFileOptions;
RptDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
RptDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
RptDoc.Export();
}
catch(Exception exobj)
{
fileFullName = string.Empty;
throw exobj;
}
finally
{
RptDoc.Close();
} public void ExportToExplorer(string contentType, string fileName, string fileFullName)
{
if (File.Exists(fileFullName))
{ // Get length of file
long fileLength = new FileInfo(fileFullName).Length; // Clear response information
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ClearHeaders(); // Set encoding format
HttpContext.Current.Response.Charset = "UTF-8";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8; // Add header information to response
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
HttpContext.Current.Response.AddHeader("Context-Length", fileLength.ToString()); // Set content type
HttpContext.Current.Response.ContentType = contentType; // Export report to explorer
HttpContext.Current.Response.WriteFile(fileFullName);
HttpContext.Current.Response.Flush();
}
}