如何将日期晶体报告转换为PDF ASP.NET(c#) [英] how to convert date Cryctal Report to PDF ASP.NET(c#)

查看:82
本文介绍了如何将日期晶体报告转换为PDF ASP.NET(c#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生

我是Shailendra singh,我更新鲜,而且我不从事以下工作.如何在asp.net中将Crystal Report转换为PDF文件.但是我的数据库在线.请任何人帮助我.





在此先感谢您.

Dear sir

I am Shailendra singh ,I am fresher and I am not doing following work.How can convert crystal Report to PDF File in asp.net.But My database is online .Please any one help me.





Thank you In Advance.

推荐答案

您好Shailendra,

Crystal Report提供了内置的方法,可以将其转换为不同的格式

绑定水晶报表后,下面是将其导出为pdf格式的代码.
ExportOptions exportOpts = doc.ExportOptions;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.DestinationOptions =新的DiskFileDestinationOptions();
Hi Shailendra,

There is built in methods available from crystal report to convert it into different formats

After binding your crystal report below is the code for exporting it into pdf format.
ExportOptions exportOpts = doc.ExportOptions;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.DestinationOptions = new DiskFileDestinationOptions();
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
            ( ( DiskFileDestinationOptions )doc.ExportOptions.DestinationOptions ).DiskFileName = Server.MapPath("fin.pdf");
            doc.Export();
            Response.Write(dt.Rows.Count);
            Response.Write("<a href=\"" + pdfFile + "\">" + pdfFile + "</a>"


);


如果要选择导出格式,则在Crystal Report Viewer中内置选项.

希望这有助于


);


If you want to provide selection of export format there is built in option in crystal report viewer.

Hope this helps


Crystal报表本身支持此功能.据我所知,您只需要导出水晶报表,它就会询问格式和路径
Crystal reports itself support this . As far as i know you just need to export crystal report and it will ask for the format and path


您好Shailendra,

要将Crystal Report转换为PDF,请执行以下步骤:

将Crystal Report View添加到您的页面

并尝试我的代码进行转换

DataTable dt = new DataTable();

//在Datatable下面调用您的类和方法,
dt = Designation.fillgrid();
尝试
{
如果(dt.Rows.Count& gt; 0)
{
ReportDocument rptdoc = new ReportDocument();
//在这里,您将给出您的路径,就像我给了There文件夹报告一样,其中保存了DesignationReport.rpt

rptdoc.Load(Server.MapPath(〜\\ Report \\ DesignationReport.rpt"));
rptdoc.SetDataSource(dt);

//crv是Crystal Report查看器的ID
crv.ReportSource = rptdoc;
crv.DataBind();


ExportOptions exportOpts1 = rptdoc.ExportOptions;
rptdoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
rptdoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
rptdoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
(((DiskFileDestinationOptions)rptdoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("DesignationReport.pdf");
rptdoc.Export();
rptdoc.Close();
rptdoc.Dispose();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType =应用程序/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename = DesignationReport.pdf");
Response.WriteFile("DesignationReport.pdf");
Response.Flush();
Response.Close();
System.IO.File.Delete(Server.MapPath("DesignationReport.pdf"));
}
其他
{
Messagebox1.Show(该区域没有记录");
}
}
赶上{}
}

尝试上述代码后,给出反馈
Hi Shailendra,

To convert Crystal Report into PDF u have follow some steps:

Add Crystal Report View into ur page

and the try my code to convert

DataTable dt = new DataTable();

//below Datatable call ur class and method,
dt = Designation.fillgrid();
try
{
if (dt.Rows.Count &gt; 0)
{
ReportDocument rptdoc = new ReportDocument();
//here u will give ur path Like I have give There folder report in which I kept the DesignationReport.rpt

rptdoc.Load(Server.MapPath("~\\Report\\DesignationReport.rpt"));
rptdoc.SetDataSource(dt);

//crv is the ID of crystal Report viewer
crv.ReportSource = rptdoc;
crv.DataBind();


ExportOptions exportOpts1 = rptdoc.ExportOptions;
rptdoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
rptdoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
rptdoc.ExportOptions.DestinationOptions = new DiskFileDestinationOptions();
((DiskFileDestinationOptions)rptdoc.ExportOptions.DestinationOptions).DiskFileName = Server.MapPath("DesignationReport.pdf");
rptdoc.Export();
rptdoc.Close();
rptdoc.Dispose();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=DesignationReport.pdf");
Response.WriteFile("DesignationReport.pdf");
Response.Flush();
Response.Close();
System.IO.File.Delete(Server.MapPath("DesignationReport.pdf"));
}
else
{
Messagebox1.Show("No Record for this District");
}
}
catch { }
}

After trying above code give feedbacks


这篇关于如何将日期晶体报告转换为PDF ASP.NET(c#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆