Crystal Reports: Passing Multiline Parameter Value

2019-07-18 03:36发布

I want to pass some parameters to a Crystal Report like this:

ReportDocument.DataDefinition.FormulaFields[parameterName].Text   = 'Text';

This workes fine unless I want to pass a multiline textbox from ASPX (containing \n and \r chars.)

The reportviewer reports that "The matching ' for this string is missing.".

Is there any example/list/suggestion how to parse the (multiline) text and make this work?

Thanks,

Stefan

3条回答
何必那么认真
2楼-- · 2019-07-18 03:54

You have to replace the \r\n pair with something obscure before passing it to the report, then make a crystal formula that converts it back to cr-lf pair in the report.

Example with converting cr-lf to three underscores

C#

ReportDocument.DataDefinition.FormulaFields[somefield].Text = textWithCrLf.Replace("\r\n","___");

Crystal formula:

Replace({somefield}, "___", chr(13))

查看更多
Deceive 欺骗
3楼-- · 2019-07-18 04:16

If you want to retain line breaks you should replace them with something obscure as described by sindre j. In order for the line breaks to display correctly in Crystal Reports you need to replace the obscure characters in a Crystal Report formula with html breaks. Then add your formula field to the report and right-click, select 'Format Field', select the 'Paragraph' tab, and change the 'Text Interpretation' to 'HTML Text'. You also need to make sure the 'Can Grow' attribute is checked on the 'Common' tab. See the example formula below:

"<html>" + Replace({?ParameterField}, "___", "<br>") + "<html/>"

Hope this helps.

查看更多
做个烂人
4楼-- · 2019-07-18 04:16

Regardless of your parsing technique, you may want to use the Parameter's DefaultValues or CurrentValues collections. The DefaultValues collection populates the list of available values. The CurrentValues collection populates the list of selected values.

查看更多
登录 后发表回答