Crystal reports 打印不带对话框的报告

Crystal reports 打印不带对话框的报告,crystal-reports,ole,powerbuilder,Crystal Reports,Ole,Powerbuilder,我的PrintReport功能正常,但我希望在不创建对话框的情况下直接将报告从PowerBuilder打印到默认打印机。我怎样才能做到这一点?我还可以同时指定页面范围吗 我使用Crystal Reports 11.5和PowerBuilder 12.5 PowerBuilder没有“PrintReport”方法。不确定这是应用程序代码还是Crystal中的内容。如果正在打印数据窗口,可以检查“打印规范-打印前提示”选项。1-在正在工作的窗口中声明实例变量 String module String

我的
PrintReport
功能正常,但我希望在不创建对话框的情况下直接将报告从PowerBuilder打印到默认打印机。我怎样才能做到这一点?我还可以同时指定页面范围吗


我使用Crystal Reports 11.5和PowerBuilder 12.5

PowerBuilder没有“PrintReport”方法。不确定这是应用程序代码还是Crystal中的内容。如果正在打印数据窗口,可以检查“打印规范-打印前提示”选项。

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\u reports\u by\u company\u module.rpt”
整数对象Id
g_ole_crx_应用程序=创建对象
gi_return=g_ole_crx_application.ConnectToNewObject('CrystalDesignRunTime.application.11')
如果gi_返回值小于0,则
MessageBox(“错误”,“未连接到Crystal report”)
返回
其他的
gs_rpt_filename=LoadFile
g_ole_crx_report=g_ole_crx_application.OpenReport(gs_rpt_文件名)
//如果报告文件不存在或发生错误,则返回0。
如果结束
queryString=g_ole_crx_report.ApplicationName
g_ole_crx_连接_信息=
g_ole_crx_报表.数据库.表[1].连接属性
g_ole_crx_connection_info.deleteAll
//g_ole_crx_report_controls=g_ole_crx_report.PageGenerator.Pages
字符串ConnectInfo=“”
//删除连接属性后,添加新的连接属性
g_ole_crx_connection_info.add(“数据源”,SQLCA.ServerName)
g_ole_crx_connection_info.add(“初始目录”,SQLCA.Database)
g_ole_crx_connection_info.add(“数据库类型”、“ole DB(ADO)”)
g_ole_crx_connection_info.add(“提供者”、“SQLNCLI10”)
g_ole_crx_connection_info.add(“用户ID”,SQLCA.logid)
g_ole_crx_connection_info.add(“密码”,SQLCA.logpass)
ConnectInfo+=“Provider='SQLNCLI10';数据源='”“+SQLCA.ServerName+”;”
ConnectionInfo+=“初始目录=”“+SQLCA.Database+””;DatabaseType='OLE DB(ADO)'
ConnectInfo+=“用户ID=“+SQLCA.logid+”;密码=“+SQLCA.logpass”
g_ole_crx_connection_info.add(“ConnectInfo”,ConnectInfo)
g_ole_crx_report.database.Verify
//添加参数(如果有)
//g_ole_crx_报表。参数字段。GetItemByName(“组件代码”)。AddCurrentValue(“C001”)
//以下是在不使用“打印”对话框的情况下将打印发送到打印机的方法
//第一套打印机
g_ole_crx_报告。选择打印机(“HP LaserJet 2200系列PCL 5”、“HP LaserJet 2200系列PCL 5”、“LPT1”)
//现在使用打印输出方法
g_ole_crx_report.PrintOut(假,1,真,1,1)
//如果您有用于查看crystal report的可插入控件,则可以使用ReportSource和ViewReport
//我把它放在一个名为ole_view的标签页中
//确保还设置了源
//tab_1.tp_preview.ole_view.object.ReportSource(g_ole_crx_报表)
//选项卡_1.tp_preview.ole_view.object.ViewReport
/参考PDF:水晶报告席技术参考指南
//希望这能奏效

对于PowerBuilder中的Crystal报表,我使用OleObject,并将ConnectToneObject用于CrystalRuntime.Application。连接成功,并已查看报告。嵌入式报表查看器附带的默认工具栏中有“打印”按钮。该工具栏按钮工作正常,并打开对话框以选择打印机并将打印发送到所选打印机。我想在没有打印对话框的情况下打印报告。我找到了这个问题的解决办法。只剩下133个字符,所以我需要在本页的答案部分发布详细信息。PrintReport是可插入crystal reports ActiveX控件的方法。如果没有ActiveX控件,它将无法与PowerBuilder一起工作。还有一个问题我正在努力解决。如何获取crystal report的总页数?上述代码中的打印输出函数仅将第一页发送到打印机(最后两个参数1,1)。如果假设有3页我要发送到打印机,则函数的最后两个参数应为1,3。语法是:PrintOut([promptUser]、[numberOfCopy]、[collated]、[startPageN]、[stopPageN])还请注意,connecttoneObject函数正在连接到('CrystalDesignRunTime.Application.11')。PrintOut方法需要CrystalDesignRunTime。仅更新:PrintOut方法不需要CrystalDesignRunTime。该方法适用于CrystalRuntime.Application.xx。
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