SAP Knowledge Base Article - Public

1206822 - How to modify the text in a TextObject using Report Application Server and Visual Basic .NET


How do I modify the text in a TextObject using Report Application Server (RAS) and Visual Basic .NET?


The TextObject contains a Paragraphs collection. Each Paragraph can be considered a new line in the TextObject. Each Paragraph has a ParagraphElements collection. Each ParagraphElement can be a string, or a type of field. A single string or word can have several elements.

For example, if "Hello World" is typed into a TextObject, there would be one ParagraphElement. If the font for the word "World" is made bold (World), there are now two ParagraphElements.


Use the following sample code to modify the TextObject. This sample assumes that the text object has a single Paragraph with a single ParagraphElement.

'Current TextObject.
Dim boTextObject As CrystalDecisions.ReportAppServer.ReportDefModel.TextObject
'New Paragraph
Dim boParagraph As New Paragraph
'New ParagraphElement
Dim boParagraphTextElement As ParagraphTextElement
'Get the current ReportObject by name and cast as a TextObject
boTextObject = CType(boReportClientDocument.ReportDefController.ReportDefinition.FindObjectByName("Title"), CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)
'Get the first ParagraphElement in the first Paragraph of the TextObject.
'This way the font information is preserved.
boParagraphTextElement = boTextObject.Paragraphs(0).ParagraphElements(0)
'Set the text for the ParagraphElement.
boParagraphTextElement.Text = "New Title"
'Add the ParagraphElement to the new Paragraph
'Remove the existing Paragraphs
'Add the new Paragraph
'Modify the TextObject
'The first parameter is the ReportObject to modify
'The second parameter is the modified ReportObject.
'In this case they can be the same object.
boReportClientDocument.ReportDefController.ReportObjectController.Modify(boTextObject, boTextObject)

See Also

If there is a newline\ line feed in the text object or text is spread across more than 1 line then eacxh line is treated as 1 paragraph. If you want to modify text over multiple lines you have to edit the text of the ParagraphTextElement for each Paragraph.

Here is a sample code snippet:

Dim obj As CrystalDecisions.ReportAppServer.ReportDefModel.TextObject = CType(rcd.ReportDefController.ReportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindText)(0), CrystalDecisions.ReportAppServer.ReportDefModel.TextObject)

Dim i As Integer 

For i = 0 To obj.Paragraphs.Count - 1

Dim boParagraphTextElement As ParagraphTextElement = obj.Paragraphs(i).ParagraphElements(0)

boParagraphTextElement.Text = "new Text"

boParagraphTextElement.Kind = CrParagraphElementKindEnum.crPararaphElementKindText

Dim newParagraph As Paragraph = new Paragraph()





rcd.ReportDefController.ReportObjectController.Modify(obj, obj)


RAS, TextObject, Text, change, modify, set , 9481490 , KBA , BI-DEV-NET-CMC , Obsolete, not used anymore , How To


SAP Crystal Reports XI ; SAP Crystal Reports XI R2 ; SAP Crystal Reports, version for Visual Studio .NET 2005 ; SAP Crystal Reports, version for Visual Studio .NET 2008 ; SAP Crystal Reports, version for Visual Studio .NET 9.1