且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将.rpt转换为.pdf,.xls文件

更新时间:2023-01-31 13:38:59



可能以下代码将对您有所帮助.将您加载的报告文件传递给以下函数,可能会打开一个pdf文件.

Hi,

May be the following code will help you. Pass your loaded report file to the following function and probably it would open a pdf file.

Private Sub PrintInAcrobat(ByVal rptDoc As ReportDocument)
            Dim Fname As String
            Dim crExportOptions As ExportOptions
            Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
            rptDoc.PrintOptions.PaperSize = PaperSize.PaperA4
            rptDoc.PrintOptions.PaperOrientation = PaperOrientation.Portrait
            Fname = Server.MapPath(".") & "\" & Session.SessionID.ToString & ".pdf"
            crDiskFileDestinationOptions = New DiskFileDestinationOptions
            crDiskFileDestinationOptions.DiskFileName = Fname
            crExportOptions = rptDoc.ExportOptions
            With crExportOptions
                .DestinationOptions = crDiskFileDestinationOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
            End With
            rptDoc.Export()
            Response.ClearContent()
            Response.ClearHeaders()
            Response.ContentType = "application/pdf"
            Response.WriteFile(Fname)
            Response.Flush()
            Response.Close()
            System.IO.File.Delete(Fname)
        End Sub



希望对您有帮助!



Hope it helps!!


您好,
在我的Web项目中,使用了内置打印选项中的Crystal Reports
并在打印时打开一个新的Web窗口,其中选择了All或Pages选项
如果页面选项可以输入在从"和到"文本框中选择的值
我想获取这些值以输入数据库,但是找不到内置打印按钮的任何事件

所以我决定使用自己的打印按钮
这将打开一个新窗口,从中我将选择全部"或页面"
以及如果从发件人"和到"文本框中选择了"Pages"值, 我要从哪个页面到哪个页面以pdf
记录
我在解决方案1中使用了上面的代码将报告转换为PDF
这将转换在report(.rpt)中打开的所有记录
我只想转换几条记录,例如
仅第4到第8名
请提出建议.

问候
Ankit
Hi,
In my web project crystal reports in built print option was used
and on print a new web window gets opened in which All or Pages option is selected
If pages option selected values in From and To text box can be entered
I want to get these values to enter in to my database but could not find any event for inbuilt print button

So i decided to go with my own print button
which will open a new window from where i will select ALL or Pages
and if Pages is selected values in From and To textbox
that is from which page to which page i want my records in pdf

I used the above code in solution 1 to convert my report in to PDF
this converts all the records which are opened in report(.rpt)
i want to convert only few records like
4th to 8th only
Please suggest.

Regards
Ankit


你好
您可以将晶体repport导出为指定的格式(.pdf)
使用此代码

CrystalReport1 cr =新的CrystalReport1();

字符串n ="c:\您的指定位置";
cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat,n);
hello
you can export a crystal repport to the specified format (.pdf)
with this code

CrystalReport1 cr = new CrystalReport1();

string n = "c:\your specified location";
cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, n);