如何在VB.NET中以编程方式将水晶报表导出为PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14335966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to programatically export crystal report as PDF in VB.NET
提问by
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports CrystalDecisions.Web
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.CrystalReports
Imports System.IO
Imports System.Net
Imports System.Net.Mail
Public Class Form1
Dim cryRpt As New ReportDocument
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cryRpt.Load("C:\Documents and Settings\Prs1\My Documents\Visual Studio 2008\Projects\myCR\myCR\cr.rpt")
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()
Try
Dim CrExportOptions As ExportOptions
Dim CrDiskFileDestinationOptions As New _
DiskFileDestinationOptions()
Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
CrDiskFileDestinationOptions.DiskFileName = _
"C:\crystalExport.pdf"
CrExportOptions = cryRpt.ExportOptions
With CrExportOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
.DestinationOptions = CrDiskFileDestinationOptions
.FormatOptions = CrFormatTypeOptions
End With
cryRpt.Export()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
End Class
结束类
I tried the above code. I have one Windows Form and a single Crystal report file (cr.rpt) in my project folder. I'm using Oracle 10G as the database. But I'm getting an error saying that "Logon Failed". ([Error Description]Image: http://pho.to/Zv6t)
我试过上面的代码。我的项目文件夹中有一个 Windows 窗体和一个 Crystal 报表文件 (cr.rpt)。我使用 Oracle 10G 作为数据库。但是我收到一条错误消息,说“登录失败”。([错误说明]图片:http: //pho.to/Zv6t)
Pls do help.
请帮忙。
采纳答案by
回答by shiwendra
This usual problem happens only to the Older version of CrystalReports caller from VB to .Net world.
这个通常的问题只发生在从 VB 到 .Net 世界的旧版 CrystalReports 调用者。
Nothing to worry. Please use like this.........
没什么好担心的。请这样使用......
connectionInfo.DatabaseName = "MahendrenDataBase"
connectionInfo.ServerName ="SystemDSN";//Create a system dsn.
connectionInfo.UserID = "UID";
connectionInfo.Password="Pwd"
回答by YOGESH SANKAR
Imports CrystalDecisions.CrystalReports.Engine
进口 CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
进口 CrystalDecisions.Shared
Dim rpt As New RptCashbill
Dim rpt As New RptCashbill
''''''fill Report data''''''
CType(rpt,ReportDocument).ExportToDisk(ExportFormatType.PortableDocFormat,"C:/Report.pdf")

