水晶报表10 rdc 动态生成水晶报表 添加删除分组

水晶报表10 rdc 动态生成水晶报表 添加删除分组

The information in the article refers to:
Seagate Crystal Reports 8

Applies to:

Reported version only
Report Creation API
Adding and deleting groups in a report

Synopsis

This article is part of a series of Knowledge Base articles that demonstrate the Report Creation API (RCAPI) available in the Report Designer Component for Crystal Reports Version 8 Developer Edition.

For more articles on using the Report Designer Component's Report Creation API search on the keyword RCAPI.

This article demonstrates how to:
- Create a report at runtime (RCAPI Method: 'NewReport')
- Add a table from a Native connection to Microsoft Access. (RCAPI Method: 'Add')
- Add a group to the report.
- Delete a group from the report. (RCAPI Method: 'DeleteGroup')
- Add database fields to the report. (RCAPI Method: 'AddFieldObject')
- Display the report.

Note=====
All Runtime Report Creation functionality requires licensing. For more information, please visit http://www.crystaldecisions.com/products/crystalreports/license.
=========

Solution

This tutorial assumes that the developer has prior knowledge of Microsoft Visual Basic, Crystal Reports, and the Report Designer Component.

The following procedure and sample code creates an application that demonstrates the RCAPI methods outlined in the Synopsis.

1. On the 'Project' menu in Microsoft Visual Basic click 'References'. The 'References' dialog box appears.

2. In the dialog box select the 'Crystal Report 8 ActiveX Designer Run Time Library' check box. Click 'OK' to save the changes.

3. On the 'Project' menu, click 'Components'. The 'Components' dialog box appears.

4. In the dialog box click 'Controls', select the 'Crystal Report Viewer' check box and then click 'Apply'. This adds the CRViewer icon to the Microsoft Visual Basic toolbar. Click 'OK' to save the changes.

5. On the Microsoft Visual Basic toolbar double-click 'CRViewer'. The Crystal Report Viewer is added to the form.

6. Double-click 'Form1' to open the 'Code' module. Insert the 'Sample RDCAPI code' in the code module.

7. Once you have inserted the code, on the 'Run' menu, click 'Start' to run the application.

Note===========
For more information on the RCAPI refer to the 'Seagate Crystal Reports 8 Technical Reference Guide'. The guide can be found in the Docs folder of the Crystal Report 8 installation CD.
===============

Option Explicit

'RDC Runtime Objects used in this sample.
Dim crApplication As CRAXDRT.Application
Dim crReport As CRAXDRT.Report

'=====================
'The Form_Load event creates an instance of the RDC engine,
'then makes calls to routines that will setup the report and
'finally display the report in the Crystal Report Viewer
'control.
'=====================
Private Sub Form_Load()

'Create an instance of the RDC engine
Set crApplication = New CRAXDRT.Application

'Create a new report
Set crReport = crApplication.NewReport

'Calling a routine that will add a database connection for the report
Call AddDatabase

'Calling a routine that will add objects to the Detail section.
Call AddToDetails

'Calling a routine that will add group to the report.
Call AddGroup

'Set the Report Viewer control to a report to view
CRViewer1.ReportSource = crReport
'Display the report in the Crystal Report Viewer
CRViewer1.ViewReport

End Sub

'=====================
'cmdDeleteGroup_Click() is a button click event that deletes
'the group added in the AddGroup() routine then sets and
'refreshes the Report Viewer to display the report without the group
'or group tree.
'=====================
Private Sub cmdDeleteGroup_Click()

'Delete the group added in the AddGroup() routine.
'The GroupNumber parameter is an integer value representing
'the group to delete. The value is 1 based.
'Note the GroupNumber property for the AddGroup method
'of the Report object is 0 based.
'When the group is added the GroupNumber is 0
'When the group is deleted theGroupNumber is 1
crReport.DeleteGroup 1

'Disable the group tree
CRViewer1.EnableGroupTree = False
'Refresh the report. The report will display
'Without the group or group tree.
CRViewer1.Refresh

'Disable the cmdDeleteGroup button
cmdDeleteGroup.Enabled = False
End Sub

'=====================
'The AddDatabase() routine is used to add a native database
'connection to the sample database, Xtreme.MDB. In this
'sample the 'Customer' table is being added.
'=====================
Public Sub AddDatabase()
'Variables used to setup the Database connection
Dim crDBTables As CRAXDRT.DatabaseTables
Dim sDatabasePath As String
Dim sTableName As String

'Get the Tables collection because it has the Add() method needed
'to add a connection to the report
Set crDBTables = crReport.Database.Tables

'Set the values for the connection variables
'The full path and name of the Access database.
'The database resides in the same directory as the application
sDatabasePath = App.Path & "/xtreme.mdb"


'The name of the Access table
sTableName = "Customer"

'Use the .Add() method to add the database table to the report.
'There are several optional arguments for the Add method. Which arguments are passed
'will depend on the type of database, the type of table and the type of connection.

'Add the 'Customer' table
crDBTables.Add sDatabasePath, sTableName
End Sub

'=====================
'The AddToDetails () routine is used to add objects to the
'Detail section. In this case, two fields from the 'Customer'
'table are added.
'=====================
Public Sub AddToDetails()
Dim crSection As CRAXDRT.Section
Dim crFieldObject As CRAXDRT.FieldObject

'****Add database fields to the Details section*****

'Since we are working with the Details section of the report, we need
'to get the 'D' section of the report.
Set crSection = crReport.Sections.Item("D")

'**Add the 'Customer Name and 'Last Year's Sales' fields to the details section**
'Set a Field object to the AddFieldObject method of the Detail Section
'The Field parameter is set to the table.fieldname
'The Left and Top parameters are passed as integers to position the field
Set crFieldObject = crSection.AddFieldObject("{Customer.Customer Name}", 600, 0)

Set crFieldObject = crSection.AddFieldObject("{Customer.Last Year's Sales}", 3720, 0)

End Sub

'=====================
'The AddGroup () routine is used to add a group to the
'report. In this case a group based on the 'Country'
'field of the 'Customer' table will be added.
'=====================
Public Sub AddGroup()
Dim crDatabaseField As CRAXDRT.DatabaseFieldDefinition
Dim crField As CRAXDRT.FieldObject
Dim crSection As CRAXDRT.Section

'Set the database field to the 'Country' field of
'the 'Customer' table.
Set crDatabaseField = crReport.Database.Tables(1).Fields(13)

'Add a group to the report.
'The GroupNumber parameter is the number of the group added and is 0 based
'The pConditionField parameter is the DatabaseFieldDefinition object set to crxDatabaseField
'The Condition parameter is grouping condition and is set to group on any value
'The SortDirection parameter is the sorting direction for the group
crReport.AddGroup 0, crDatabaseField, crGCAnyValue, crAscendingOrder

'***Add the 'Country' field to the Group Header***

'Since we are working with the Group Header section, we need
'to get the 'GH' section of the report.
Set crSection = crReport.Sections.Item("GH")

'Set a Field object to the AddFieldObject method of the Group Header Section
'The Field parameter is set to the table.fieldname
'The Left and Top parameters are passed as integers to position the field

Set crField = crSection.AddFieldObject("{Customer.Country}", 100, 0)
End Sub

'=====================
'The Form_Resize event is used to size the Crystal Report
'Viewer control to the size of the Parent form (Form1).
'=====================
Private Sub Form_Resize()

With CRViewer1
.Top = 0
.Left = 0
.Width = Me.ScaleWidth
'Adjust the height to allow room for the
'cmdDeleteGroup button
.Height = Me.ScaleHeight - 700
End With

'Reset the cmdDeleteGroup button Top.
cmdDeleteGroup.Top = Me.ScaleHeight - 600

End Sub

'=====================
'The Form_Unload event is used to clean up the objects
'used by the sample application.
'=====================
Private Sub Form_Unload(Cancel As Integer)

'Destroy the Report object
Set crReport = Nothing

'Destroy the Application object
Set crApplication = Nothing

End Sub

摘自 http://www.businessobjects.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值