gpt4 book ai didi

c# - 使用 Crystal 报表导出为pdf文件

转载 作者:太空狗 更新时间:2023-10-30 00:15:06 25 4
gpt4 key购买 nike

我这里有代码示例,我可以直接保存为 PDF 文件,但我想做的是首先向客户端显示 pdf 文件,并允许用户保存它。我如何实现这一点?

ReportDocument rpt = new ReportDocument();
rpt.Load(@"C:\CrystalReport2.rpt");

rpt.SetDataSource(datatablesource);

ExportOptions rptExportOption;
DiskFileDestinationOptions rptFileDestOption = new DiskFileDestinationOptions();
PdfRtfWordFormatOptions rptFormatOption = new PdfRtfWordFormatOptions();
string reportFileName = @"C:\SampleReport.pdf";
rptFileDestOption.DiskFileName = reportFileName;
rptExportOption = rpt.ExportOptions;
{
rptExportOption.ExportDestinationType = ExportDestinationType.DiskFile;
//if we want to generate the report as PDF, change the ExportFormatType as "ExportFormatType.PortableDocFormat"
//if we want to generate the report as Excel, change the ExportFormatType as "ExportFormatType.Excel"
rptExportOption.ExportFormatType = ExportFormatType.PortableDocFormat;
rptExportOption.ExportDestinationOptions = rptFileDestOption;
rptExportOption.ExportFormatOptions = rptFormatOption;
}

rpt.Export();

最佳答案

这是我的代码:

dbObj = new ConnectDB();
query = "SELECT Student.*, School.*FROM Student where admissionnumber = '" + reg_number + "'";
DataSet ds = dbObj.Fetch_Data(query, "DataView");
ReportDocument rd;
rd = new ReportDocument();
rd.Load(Application.StartupPath + "\\StudentReg.rpt");
//rd.Load("StudentReg.rpt");
rd.SetDataSource(ds);
crv.ReportSource = rd;
crv.Refresh();
if(File.Exists(@"D:\" + reg_number + ".pdf"))
File.Delete(@"D:\" + reg_number + ".pdf");
rd.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, @"D:\" + reg_number + ".pdf");

关于c# - 使用 Crystal 报表导出为pdf文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17094822/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com