Software used:
This is a continuation of the story of Jason who was a meager trainee in a middle level organization. He was generally given boring and lengthy manual work, but he always tried to make his job fast, intelligent and interesting.
Some time back, he had generated an excel sheet containing details of all the 762 crystal reports used by his organization. This week Mr. Murphy told him that the higher management had decided to deploy these reports for the far-east operations based on his analysis. So, a minor change needed to be made for all the reports. The font for all the database field objects in the detail section needed to be changed to “Arial Unicode MS” so that there was no problem displaying multi-language data. So Jason was required to right-click on each field object, go to fonts tab and change the font name to “Arial Unicode MS”.
The task was simple no doubt, but Jason was not interested in doing so much manual work, and again planned to make all the changes by a simple button click in his automated VB dot net application.
So the list of events that occurred when he clicked on the button would be as follows:
Dim folderPath As String
Dim fileNames As Object
Dim rdoc As CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim rasClientDoc As CrystalDecisions.ReportAppServer.ClientDoc.ISCDClientDocument
Dim oldObject As CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject
Dim changedObject As CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject
Dim myFont As CrystalDecisions.ReportAppServer.ReportDefModel.Font
'This is the Font to be set
myFont = New CrystalDecisions.ReportAppServer.ReportDefModel.Font
myFont.Name = "Arial Unicode MS"
FolderBrowserDialog1.SelectedPath = "c:\"
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
folderPath = FolderBrowserDialog1.SelectedPath
'Only report files from selected directory are to be analysed
fileNames = My.Computer.FileSystem.GetFiles(
folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.rpt")
For Each fileName As String In fileNames
rdoc = New CrystalDecisions.CrystalReports.Engine.ReportDocument
rdoc.Load(fileName)
rasClientDoc = rdoc.ReportClientDocument
'Iterate through all objects in the detail section
For i = 0 To rasClientDoc.ReportDefController.ReportDefinition.DetailArea.Sections(0).ReportObjects.Count() - 1
oldObject = CType(rasClientDoc.ReportDefController.ReportDefinition.DetailArea.Sections(0).ReportObjects(i), CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject)
'Check whether the reportobject is a database field, then change its font
If oldObject.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrReportObjectKindEnum.crReportObjectKindField Then
changedObject = CType(rasClientDoc.ReportDefController.ReportDefinition.DetailArea.Sections(0).ReportObjects(i).Clone(True), CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)
changedObject.FontColor.Font.Name = myFont.Name
rasClientDoc.ReportDefController.ReportObjectController.Modify(oldObject, changedObject)
End If
Next
rasClientDoc.Save()
Next
End If
Note:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
5 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |