2017-01-23 78 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

相關問題