on 10-07-2010 12:03 PM
I need to change the font of text and field objects at runtime. I used to do this using Crystal 10 and the craxdrt.dll, but haven't been able to get to work with Crystal 2008. Here's the code:
note: myFont is a font object passed into the procedure.
Dim rcd As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument
rcd = rpt.ReportClientDocument
For Each area As CrystalDecisions.ReportAppServer.ReportDefModel.Area In rcd.ReportDefinition.Areas
For Each section As CrystalDecisions.ReportAppServer.ReportDefModel.Section In area.Sections
For Each rptObj As CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject In section.ReportObjects
If rptObj.Kind = ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField Then
Dim rptField As ReportAppServer.ReportDefModel.FieldObject = CType(rptObj, ReportAppServer.ReportDefModel.FieldObject)
rptField.FontColor.Font.Name = myFont.Name
rptField.FontColor.Font.Size = myFont.Size
ElseIf rptObj.Kind = ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindText Then
Dim rptText As ReportAppServer.ReportDefModel.TextObject = CType(rptObj, ReportAppServer.ReportDefModel.TextObject)
rptText.FontColor.Font.Name = myFont.Name
rptText.FontColor.Font.Size = myFont.Size
End If
Next
Next
Next
I have a couple problems. First, my rcd object does not recognize the ReportDefinition property. I can type it in and it is accepted, but it is not an option when I look at the properties avaiable to that object. When I run the code, it does not throw an error. My Crystal version is 12.2.0.290. I have included the following reference in my project:
Cyrstal Decisions.CrystalReports.Engine
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportAppServer.CommonObjectModel
CrystalDecisions.ReportAppServer.Controllers
CrystalDecisions.ReportAppServer.DataDefModel
CrystalDecisions.ReportAppServer.ObjectFactory
CrystalDecisions.ReportAppServer.ReportDefModel
CrystalDecisions.Shared
The Engine.dll and Shared.dll are listed as version 12.0.2000.0 and are located in the c:\program files\business objects\common\4.0\managed\dotnet2 directory. The remaining dlls are listed as version 12.0.1100.0 and are located in the c:\program files\business objects\common\4.0\managed directory. Is this a problem? Do I have 2 incompatible versions?
Also, when I run the code, although it does not break, the report font is not changed. Please help.
The code you are using isn't going to work as when working with the RAS SDK model, most objects cannot be modified by directly changing their value, instead you need to use the controllers and their modify methods. Here's a sample of how to change the font size:
Dim myReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
myReport.Load(Server.MapPath("Test.rpt"))
Dim boRCD As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument = myReport.ReportClientDocument
Dim boTextObject As CrystalDecisions.ReportAppServer.ReportDefModel.TextObject = CType(boRCD.ReportDefController.ReportObjectController.GetAllReportObjects().Item("Text1"), CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)
boTextObject.FontColor.Font.Size = 24
boRCD.ReportDefController.ReportObjectController.Modify(CType(boRCD.ReportDefController.ReportObjectController.GetAllReportObjects().Item("Text1"), CrystalDecisions.ReportAppServer.ReportDefModel.TextObject), boTextObject)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you both for your response. I had an Imports CrystalDecisions statement at the top of my code, but I went ahead and added the qualifier anyway. The real solution was to use the controller. So this is my modified code (works quite well - thanks much).
Dim rcd As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument
rcd = rpt.ReportClientDocument
For Each area As CrystalDecisions.CrystalReports.Engine.Area In rpt.ReportDefinition.Areas
For Each section As CrystalDecisions.CrystalReports.Engine.Section In area.Sections
For Each obj As CrystalDecisions.CrystalReports.Engine.ReportObject In section.ReportObjects
If obj.Kind = CrystalDecisions.Shared.ReportObjectKind.FieldObject Then
Dim objField As CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject = CType(rcd.ReportDefController.ReportObjectController.GetAllReportObjects().Item(obj.Name), CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)
objField.FontColor.Font.Name = myFont.Name
objField.FontColor.Font.Size = myFont.Size
rcd.ReportDefController.ReportObjectController.Modify(CType(rcd.ReportDefController.ReportObjectController.GetAllReportObjects().Item(obj.Name), CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject), objField)
ElseIf obj.Kind = CrystalDecisions.Shared.ReportObjectKind.TextObject Then
Dim objText As CrystalDecisions.ReportAppServer.ReportDefModel.TextObject = CType(rcd.ReportDefController.ReportObjectController.GetAllReportObjects().Item(obj.Name), CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)
objText.FontColor.Font.Name = myFont.Name
objText.FontColor.Font.Size = myFont.Size
rcd.ReportDefController.ReportObjectController.Modify(CType(rcd.ReportDefController.ReportObjectController.GetAllReportObjects().Item(obj.Name), CrystalDecisions.ReportAppServer.ReportDefModel.TextObject), objText)
End If
Next
Next
Next
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
First thing you should fully qualify these:
If rptObj.Kind = ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField Then
Dim rptField As ReportAppServer.ReportDefModel.FieldObject = CType(rptObj, ReportAppServer.ReportDefModel.FieldObject)
Should be
If rptObj.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField Then
Dim rptField As CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject = CType(rptObj, CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)
Test again
Thank you
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.