我的PrintReport
功能有效,但我想直接从PowerBuilder打印报告到默认打印机,而不用创建一个对话框。我怎么能做到这一点?我也可以同时指定页面范围吗?
我使用的是Crystal Reports 11.5和PowerBuilder 12.5。
答案 0 :(得分:0)
PowerBuilder没有'PrintReport'方法。不确定这是应用程序代码还是Crystal中的内容。如果要打印数据窗口,可以查看“打印规格 - 打印前提示”选项。
答案 1 :(得分:0)
1-在您正在使用的窗口中声明实例变量
String module
String Folder, FileName
Datawindow theDw
OLEObject g_ole_crx_application
OLEObject g_ole_crx_report
OLEObject g_ole_crx_connection_info
OLEObject g_ole_crx_export_options
OLEObject g_ole_crx_report_controls
String gs_rpt_filename, queryString, report_folder, report_file
OLEObject myoleobject
Long gi_return
//Please remove those variables you dont need
2-在任何控件中粘贴以下内容(例如按钮)
String LoadFrom, LoadFile="C:\BT\SVN\Crystal\PB\app_reports_by_company_module.rpt"
Integer Object_Id
g_ole_crx_application = CREATE OLEObject
gi_return = g_ole_crx_application.ConnectToNewObject('CrystalDesignRunTime.Application.11')
if gi_return < 0 then
MessageBox("Error", "Not connected to Crystal report")
return
else
gs_rpt_filename = LoadFile
g_ole_crx_report = g_ole_crx_application.OpenReport(gs_rpt_filename)
//Returns 0 if the report file does not exist or if an error occurs.
end if
queryString = g_ole_crx_report.ApplicationName
g_ole_crx_connection_info =
g_ole_crx_report.database.tables[1].ConnectionProperties
g_ole_crx_connection_info.deleteAll
//g_ole_crx_report_controls = g_ole_crx_report.PageGenerator.Pages
String ConnectInfo = ""
//after deleting connection properties , add new connection properties
g_ole_crx_connection_info.add("Data Source", SQLCA.ServerName)
g_ole_crx_connection_info.add("Initial Catalog", SQLCA.Database)
g_ole_crx_connection_info.add("Database Type", "OLE DB (ADO)")
g_ole_crx_connection_info.add("Provider", "SQLNCLI10")
g_ole_crx_connection_info.add("User ID", SQLCA.logid)
g_ole_crx_connection_info.add("Password", SQLCA.logpass)
ConnectInfo += "Provider='SQLNCLI10';Data Source='" + SQLCA.ServerName + "';"
ConnectInfo += "Initial Catalog='" + SQLCA.Database + "';DatabaseType='OLE DB (ADO)';"
ConnectInfo += "User ID=" + SQLCA.logid + ";Password=" + SQLCA.logpass
g_ole_crx_connection_info.add("ConnectInfo", ConnectInfo)
g_ole_crx_report.database.Verify
//add parameters if there are any
//g_ole_crx_report.ParameterFields.GetItemByName("comp_code").AddCurrentValue('C001')
// here is the way how you can send print to the printer without print dialog box
// first set printer
g_ole_crx_report.SelectPrinter("HP LaserJet 2200 Series PCL 5","HP LaserJet 2200 Series PCL 5", "LPT1")
// now use the PrintOut method
g_ole_crx_report.PrintOut (FALSE, 1, TRUE, 1, 1)
// if you have insertable control to view crystal report you can use ReportSource and ViewReport
// i have it in a tab page with the name ole_view
// make sure you also set the source
//tab_1.tp_preview.ole_view.object.ReportSource(g_ole_crx_report)
//tab_1.tp_preview.ole_view.object.ViewReport
// Reference pdf : Crystal Reports XI Technical Reference Guide
// that will work hopefully