2017-01-23 91 views
0

我的PrintReport函数的作品,但我想直接从PowerBuilder打印报告到默认打印机没有创建一个对话框。我怎样才能做到这一点?我也可以同时指定页面范围吗?没有对话框的打印报告

我使用Crystal Reports 11.5和PowerBuilder 12.5。

回答

0

PowerBuilder没有'PrintReport'方法。不知道这是你的应用程序代码或Crystal中的东西。如果要打印数据窗口,则可以检查打印规格 - 打印前提示选项。

+0

对于在PowerBuilder我是水晶报表使用OleObject并为CrystalRuntime.Application使用ConnectToNewObject。连接成功并查看报告。嵌入式报表查看器附带的默认工具栏中有打印按钮。该工具栏按钮正常工作并打开对话框以选择打印机并将打印发送到选定的打印机。我想在没有打印对话框的情况下打印报告。我找到了解决这个问题的办法。只剩下133个字符,所以我需要在此页面的回答部分发布详细信息。 – Berka

+0

PrintReport是可插入水晶报告ActiveX控件的方法。它不适用于没有ActiveX控件的PowerBuilder。还有一个问题需要解决。我如何获得水晶报告的总页数? – Berka

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 
+0

上述代码中的PrintOut函数仅向打印机发送第一页(最后两个参数1,1)如果假设有3页要发送给打印机,则函数的最后两个参数应为1,3语法是:PrintOut([promptUser],[numberOfCopy],[collat​​ed], [startPageN],[stopPageN]) – Berka

+0

另请注意,ConnectToNewObject函数正在连接到('CrystalDesignRunTime.Application.11')。 CrystalDesignRunTime对于PrintOut方法是必需的。 – Berka

+0

只是更新:CrystalDesignRunTime对于PrintOut方法不是必需的。该方法适用于CrystalRuntime.Application.xx。 – Berka