vb.net VB 6.0 Crystal Reports 导出为 PDF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18062033/
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
VB 6.0 Crystal Reports Export to PDF
提问by Daniel Camburn
I'm having issues with reporting a Crystal Reports file to PDF format. I've looked at all the other questions here regarding the issue but none of them seem to solve mine.
我在将 Crystal Reports 文件报告为 PDF 格式时遇到问题。我已经查看了有关该问题的所有其他问题,但似乎没有一个能解决我的问题。
Here is my code:
这是我的代码:
Public Sub ExportReportToPDF(ReportObject As CRAXDRT.Report, ByVal filename As String, ByVal ReportTitle As String)
Dim objExportOptions As CRAXDRT.ExportOptions
ReportObject.ReportTitle = ReportTitle
With ReportObject
.EnableParameterPrompting = False
.MorePrintEngineErrorMessages = True
End With
Set objExportOptions = ReportObject.ExportOptions
With objExportOptions
.DestinationType = crEDTDiskFile
.DiskFileName = filename
'.FormatType = crEFTExcel80Tabular
'.FormatType = crEFTCommaSeparatedValues
'.FormatType = crEFTExcel80
'.FormatType = crEFTHTML32Standard
'.FormatType = crEFTHTML40
.FormatType = crEFTPortableDocFormat
'.FormatType = crEFTRichText
'.FormatType = crEFTText
'.FormatType = crEFTWordForWindows
End With
ReportObject.Export False
End Sub
Now, I've left the other options besides PDF in there just to show them, they're all commented out obviously, but if I try any of the other formats, it exports just fine. The only format that doesn't export is PDF. It gives me the error:
现在,我将除 PDF 之外的其他选项留在那里只是为了显示它们,它们显然都被注释掉了,但是如果我尝试任何其他格式,它导出得很好。唯一不能导出的格式是 PDF。它给了我错误:
Run-time error '-2147190908 (80047784)': Failed to Export the Report.
运行时错误“-2147190908 (80047784)”:无法导出报告。
When I click Debug it highlights on the ReportObject.Export False line.
当我单击“调试”时,它会在 ReportObject.Export False 行上突出显示。
On another note, if I make it so the user chooses the options, I can select PDF and it still gives me the same error. Thanks for the help.
另一方面,如果我让用户选择选项,我可以选择 PDF 并且它仍然给我同样的错误。谢谢您的帮助。
(Thanks to AVD for the coding found here How to Export to a PDF file in Crystal Report?).
(感谢 AVD 在此处找到的编码如何在 Crystal Report 中导出为 PDF 文件?)。
EDIT: After going through Phillipe's responses, I was stepping through my code and noticed that after it assigned crEFTPortableDocFormat to FormatType, it auto assigns "UXFPDF.DLL" to FormatDllName. Maybe this is my problem, does anyone know how to fix this? I tried just renaming crxf_pdf.dll and also u2fpdf.dll (the one that was for 8.0 which I originally had) but that didn't work.
编辑:经过 Phillipe 的回复后,我正在逐步执行我的代码并注意到在将 crEFTPortableDocFormat 分配给 FormatType 后,它自动将“UXFPDF.DLL”分配给 FormatDllName。也许这是我的问题,有谁知道如何解决这个问题?我尝试只重命名 crxf_pdf.dll 和 u2fpdf.dll(我最初拥有的用于 8.0 的那个),但这没有用。
EDIT: Another find is that when I enable the Export Option in CRViewer91 (which shows the report correctly) and I try and export this to a pdf via this method, it does not error. However, it saves a file that is corrupted pretty much and cannot be opened.
编辑:另一个发现是,当我在 CRViewer91 中启用导出选项(正确显示报告)并尝试通过此方法将其导出为 pdf 时,它不会出错。但是,它保存了一个几乎已损坏且无法打开的文件。
EDIT: More research. The CRViewer91 doesn't appear to be able to export any format successfully. RTF and TXT return a blank document, RPT errors when trying to open.
编辑:更多研究。CRViewer91 似乎无法成功导出任何格式。RTF 和 TXT 返回空白文档,尝试打开时出现 RPT 错误。
EDIT: I think part of my problem may be that I've been using the 8.0 CRAXRT.DLL when what I actually need is the 9.0 one. I've found the one for 9.0, now how do I make it use this instead of the old one?
编辑:我认为我的部分问题可能是我一直在使用 8.0 CRAXRT.DLL,而我实际需要的是 9.0。我找到了 9.0 的那个,现在我如何让它使用这个而不是旧的?
回答by Philippe Grondier
I guess that 'filename' value does not work, either because the folder does not exist / the file name is not valid, or because you do not have the corresponding rights to create a file under this folder.
我猜 'filename' 值不起作用,要么是因为文件夹不存在/文件名无效,要么是因为您没有相应的权限在此文件夹下创建文件。
Could you try the code with some basic parameter like 'filename = "c:\test.pdf"'?
您可以尝试使用一些基本参数(如“filename = "c:\test.pdf"”)的代码吗?
My last guess: the possibility to export to pdf format needs a specific dll file under the crystal folder (does not need to be registered but needs to be here). Do you have the crxf_pdf.dll file ?
我最后的猜测:导出为pdf格式的可能性需要在crystal文件夹下有一个特定的dll文件(不需要注册但需要在这里)。你有 crxf_pdf.dll 文件吗?
EDIT:
编辑:
My last question: are you able to expor tto PDF from the Crystal GUI?
我的最后一个问题:你能从 Crystal GUI 导出 PDF 吗?
Here is a list of the crystal report files that must be distributed with a VB app, if of any help: export capabilities seem to be linked to the crxf_*.dll files
以下是必须与 VB 应用程序一起分发的水晶报告文件列表,如果有帮助的话:导出功能似乎与 crxf_*.dll 文件相关联
CRAnalyzer.dll
craxdrt.dll
crdb_ado.dll
crdeploy.reg
crheapalloc.dll
crqe.dll
crtowords_en.dll
crtslv.dll
crviewer.dll
crxf_html.dll
crxf_pdf.dll
crxf_rtf.dll
crxf_wordw.dll
crxf_xls.dll
cxlibw-1-6.dll
dbghelp.dll
exlate32.dll
ExportModeller.dll
GDIPLUS.DLL
Implode.dll
keycode.dll
msvcrt.dll
pageObjectModel.dll
querybuilder.dll
ReportRenderer.dll
riched20.dll
sscdlg.dll
sscsdk80.dll
u252000.dll
u25dts.dll
u25samp1.dll
u2dapp.dll
u2ddisk.dll
u2dmapi.dll
u2dpost.dll
u2fcr.dll
u2frdef.dll
u2frec.dll
u2fsepv.dll
u2ftext.dll
u2fxml.dll
u2l2000.dll
u2lcom.dll
u2ldts.dll
u2lexch.dll
u2lfinra.dll
ufmanager.dll
usp10.dll
webReporting.dll
回答by Daniel Camburn
I'm not exactly sure what was causing all the errors, however, I've fixed it via basically starting a new project from scratch and incorporating only the necessary references and components. I know one problem I had (which caused a TLV error) was that the CRAXDRT.dll for CR9 was in the Windows\system32 directory, and even though it was referencing that .dll, it needed to reference it from the Program Files\Common Files\CrystalDecision... directory where all the other .dlls for CR9 are located.
我不确定是什么导致了所有错误,但是,我已经通过基本上从头开始一个新项目并仅包含必要的引用和组件来修复它。我知道我遇到的一个问题(导致 TLV 错误)是 CR9 的 CRAXDRT.dll 位于 Windows\system32 目录中,即使它引用了该 .dll,它也需要从 Program Files\Common 引用它Files\CrystalDecision... CR9 的所有其他 .dll 所在的目录。
There was also a minor code change that needed to be done, here is the finalized code that works for exporting mine to PDF.
还有一个小的代码更改需要完成,这是用于将我的代码导出为 PDF 的最终代码。
Public Sub ExportReportToPDF(ReportObject As CRAXDRT.Report, ByVal filename As String, ByVal ReportTitle As String)
Dim FormatDLLName As String
ReportObject.ReportTitle = ReportTitle
With ReportObject
.EnableParameterPrompting = False
.MorePrintEngineErrorMessages = True
End With
With ReportObject.ExportOptions
.DestinationType = crEDTDiskFile
.DiskFileName = filename
'.FormatType = crEFTExcel80Tabular
'.FormatType = crEFTCommaSeparatedValues
'.FormatType = crEFTExcel80
'.FormatType = crEFTHTML32Standard
'.FormatType = crEFTHTML40
.FormatType = crEFTPortableDocFormat
'.FormatType = crEFTRichText
'.FormatType = crEFTText
'.FormatType = crEFTWordForWindows
End With
ReportObject.Export False
End Sub
I left the commented out FormatTypes in there for anyone else who finds this code useful. Phillipe, if you would like to "answer" this somehow like this, I would love to give you some rep for all of your help that you provided however. I don't have enough rep to just upvote your stuff so.
我将注释掉的 FormatTypes 留在那里,供其他发现此代码有用的人使用。菲利普,如果你想以某种方式“回答”这个问题,我很乐意为你提供的所有帮助提供一些代表。我没有足够的代表来支持你的东西。
Thanks for all your help either way.
感谢您的所有帮助。
Dan
担

