【问题标题】:Running RPT from Crystal Reports 2008 and exporting to PDF从 Crystal Reports 2008 运行 RPT 并导出为 PDF
【发布时间】:2022-10-09 04:11:00
【问题描述】:

我正在尝试自动且无声地运行报告。

我找到了这个脚本:

#include <GUIConstants.au3>
AutoItSetOption("WinTitleMatchMode", 2)

Dim $sReportName
Dim $objCRApp
Dim $objCRReport
Dim $objCRViewer
Dim $CrystalExportOptions
Dim $ExportFileName
Dim $ExportType

$sReportName = FileOpenDialog("C:\Test\zNC\engine\Vinhos", "", "RPT (*.rpt)", 3);Filter "." means all
$objCRApp = ObjCreate("CrystalRuntime.Application.11")
If $objCRApp = 0 Then
    MsgBox(0, "Error", "Could not create CrystalRuntime Application Object")
    Exit
EndIf
$objCRReport = $objCRApp.OpenReport($sReportName)
If $objCRReport = 0 Then
    MsgBox(0, "Error", "Could not open report: " & $sReportName)
    Exit
EndIf

$objCRViewer = ObjCreate("CrystalReports11.ActiveXReportViewer.1")

; Create a simple GUI for our output
$hndReportViewer = GUICreate ( "Embedded Crystal Reports Export test", 640, 580,(@DesktopWidth-640)/2, (@DesktopHeight-580)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
If $hndReportViewer = 0 Then
    MsgBox(0, "Error", "Could not create Window to display Crystal Reports control")
    Exit
EndIf
;Creates an ActiveX control in the GUI.
$GUIActiveX = GUICtrlCreateObj ( $objCRViewer, -1, -1, 640, 580)
If $GUIActiveX = 0 Then
    MsgBox(0, "Error", "Could not create ActiveX Control in GUI")
    Exit
EndIf
GUICtrlSetResizing ( $GUIActiveX, $GUI_DOCKAUTO)

; Show GUI
GUISetState ()

$objCRViewer.ReportSource = $objCRReport

; Display the Report to watch automation
$objCRViewer.ViewReport
; The report displays a "0" in control 20005 while the report is loading
While ControlGetText("Embedded Crystal Reports printing test", "", 20005) = "0"
    Sleep(250)
WEnd

$CrystalExportOptions = $objCRReport.ExportOptions
$ExportFileName = "C:\Test\zNC\engine\Vinhos\ExportedReport.PDF"
$ExportType = 31

$CrystalExportOptions.DiskFileName = $ExportFileName
$CrystalExportOptions.FormatType = $ExportType
$CrystalExportOptions.DestinationType = 1
$objCRReport.Export ( False )
Sleep(500)
WinWaitClose("Export", "", 30)
GUIDelete()

我无法通过此连接错误。我正在使用 Microsoft SQL Server 2008 R2。

我创建的报告不需要日期范围,在 SQL 中已经这样做了。

【问题讨论】:

    标签: crystal-reports autoit crystal-reports-2008


    【解决方案1】:

    我用“ODBC 数据源”创建了一个 DSN 文件并配置到水晶报表中,我只是将 DSN 文件添加为报表的数据库连接。现在它工作了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 1970-01-01
      • 1970-01-01
      • 2010-11-23
      • 1970-01-01
      • 2015-06-22
      相关资源
      最近更新 更多