How to load RTF and HTML into Crystal Reports?
Introduction
One of the most interesting questions I got lately in the .NET Reporting forum is how you can load RTF coded text in Crystal Reports (complete with all the layout).
Crystal Reports provides functionality to interpret text as RTF or HTML. You only need to provide the data in a correct way..
Tools
-Visual Studio professional or Enterprise architect. You could also use any Visual Studio version with a separate Crystal Reports version (one that does support datasets!).
-10 minutes of time.
-Some general concepts about Crystal Reports and datasets
Tasks
-create a dataset to load the RTF, HTML and plain text.
-create a report that support this dataset
-load data in the dataset
-use the dataset as datasource for the report and show the report in the viewer
In the attachment you’ll find a fully working sample. Feel free to experiment with it and spread it around the world!
Ready?
Create a new winforms project and a dataset (dsCodedText) to it. You’ll need to include 1 table (TextCode) with three columns:
PlainText: string
RTFText: string
HTMLText: string
Creating the report is easy. Create a new report, when choosing the datasource go for the ADO.NET option and browse for the dsCodedText.xsd file in your project directory.
Now drag the three fields from your fieldexplorer in your report.
OK, now here comes the trick!
Select the RTFText field in your report, right click and choose ‘Format Field’. Select the paragraph tab. The bottom groupbox (Text interpretation) contains one combobox. Select ‘RTF Text’ from the combobox.
Select the HTMLText field in your report, right click and choose ‘Format Field’. Select the paragraph tab. The bottom groupbox (Text interpretation) contains one combobox. Select ‘HTML Text’ from the combobox.
Select the PlainText field in your report, right click and choose ‘Format Field’. Select the paragraph tab. The bottom groupbox (Text interpretation) contains one combobox. Select ‘None’ from the combobox.
In the attached sample you’ll find three simple files (one RTF, one HTML, one plain).
You’ll need to load these files as strings in your dataset (in that way, you will have both the readable text AND the markup tags).
As a side note I can remark that you only can enable this text interpretation on text that is stored in the datasource (as a string or as a memo field). You can’t enable this text interpretation on e.g. a text field or a formula...
One of the most interesting questions I got lately in the .NET Reporting forum is how you can load RTF coded text in Crystal Reports (complete with all the layout).
Crystal Reports provides functionality to interpret text as RTF or HTML. You only need to provide the data in a correct way..
Tools
-Visual Studio professional or Enterprise architect. You could also use any Visual Studio version with a separate Crystal Reports version (one that does support datasets!).
-10 minutes of time.
-Some general concepts about Crystal Reports and datasets
Tasks
-create a dataset to load the RTF, HTML and plain text.
-create a report that support this dataset
-load data in the dataset
-use the dataset as datasource for the report and show the report in the viewer
In the attachment you’ll find a fully working sample. Feel free to experiment with it and spread it around the world!
Ready?
Create a new winforms project and a dataset (dsCodedText) to it. You’ll need to include 1 table (TextCode) with three columns:
PlainText: string
RTFText: string
HTMLText: string
Creating the report is easy. Create a new report, when choosing the datasource go for the ADO.NET option and browse for the dsCodedText.xsd file in your project directory.
Now drag the three fields from your fieldexplorer in your report.
OK, now here comes the trick!
Select the RTFText field in your report, right click and choose ‘Format Field’. Select the paragraph tab. The bottom groupbox (Text interpretation) contains one combobox. Select ‘RTF Text’ from the combobox.
Select the HTMLText field in your report, right click and choose ‘Format Field’. Select the paragraph tab. The bottom groupbox (Text interpretation) contains one combobox. Select ‘HTML Text’ from the combobox.
Select the PlainText field in your report, right click and choose ‘Format Field’. Select the paragraph tab. The bottom groupbox (Text interpretation) contains one combobox. Select ‘None’ from the combobox.
In the attached sample you’ll find three simple files (one RTF, one HTML, one plain).
You’ll need to load these files as strings in your dataset (in that way, you will have both the readable text AND the markup tags).
As a side note I can remark that you only can enable this text interpretation on text that is stored in the datasource (as a string or as a memo field). You can’t enable this text interpretation on e.g. a text field or a formula...
Labels: Crystal Reports

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home