C# Crystal Reports:传递多行参数值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/324776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Crystal Reports: Passing Multiline Parameter Values
提问by
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.)
这很好用,除非我想从 ASPX 传递一个多行文本框(包含 \n 和 \r 字符。)
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
斯特凡
回答by sindre j
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.
在将它传递给报告之前,您必须用一些晦涩的东西替换 \r\n 对,然后制作一个水晶公式,将其转换回报告中的 cr-lf 对。
Example with converting cr-lf to three underscores
将 cr-lf 转换为三个下划线的示例
C#
C#
ReportDocument.DataDefinition.FormulaFields[somefield].Text = textWithCrLf.Replace("\r\n","___");
ReportDocument.DataDefinition.FormulaFields[somefield].Text = textWithCrLf.Replace("\r\n","___");
Crystal formula:
晶体配方:
Replace({somefield}, "___", chr(13))
替换({somefield},“___”,chr(13))
回答by user35193
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:
如果你想保留换行符,你应该用 sindre j 描述的一些晦涩的东西替换它们。为了在 Crystal Reports 中正确显示换行符,您需要用 html 换行符替换 Crystal Report 公式中的晦涩字符。然后将您的公式字段添加到报告中并右键单击,选择“格式字段”,选择“段落”选项卡,并将“文本解释”更改为“HTML 文本”。您还需要确保在“通用”选项卡上选中“可以增长”属性。请参阅下面的示例公式:
"<html>" + Replace({?ParameterField}, "___", "<br>") + "<html/>"
"<html>" + Replace({?ParameterField}, "___", "<br>") + "<html/>"
Hope this helps.
希望这可以帮助。
回答by craig
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.
无论您使用何种解析技术,您可能都希望使用 Parameter 的 DefaultValues 或 CurrentValues 集合。DefaultValues 集合填充可用值列表。CurrentValues 集合填充选定值的列表。