Csharp/C#教程:使用水晶报告导出为pdf文件分享


使用水晶报告导出为pdf文件

我在这里有代码示例,我可以直接保存为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(); 

 ExportOptions CrExportOptions ; DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions(); PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions(); CrDiskFileDestinationOptions.DiskFileName = "C:\SampleReport.pdf"; CrExportOptions = doc.ExportOptions; { CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat; CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions; CrExportOptions.FormatOptions = CrFormatTypeOptions; } doc.Export(); 

像这样的代码………..

这是我的代码:

上述就是C#学习教程:使用水晶报告导出为pdf文件分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 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"); 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1012456.html

(0)
上一篇 2021年12月30日
下一篇 2021年12月30日

精彩推荐