fastreport显示带[] 方括号的文本或表达式

引言

Fastreport默认使用[]标识变量及表达式,如果你显示的文本中有方括号就会报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
FastReport.TextObjectBase.CalcAndFormatExpression(String expression,Int32 expressionIndex)
FastReport.TextObject.GetData()
FastReport.BandBase.GetData()
FastReport.Engine.ReportEngine.PrepareBand(BandBase band, Boolean getData) FastReport.Engine.ReportEngine.ShowBandToPreparedPages(BandBase band, Boolean getData)
FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData)
FastReport.Engine.ReportEngine.ShowDataBand(DataBand dataBand, Int32 rowCount)
FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand, Int32 rowCount, Boolean keepFirstRow, Boolean keepLastRow)
FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand)
FastReport.Engine.ReportEngine.RunBands(BandCollection bands) FastReport.Engine.ReportEngine.RenderOuterSubreports(BandBase parentBand)
FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData)
FastReport.Engine.ReportEngine.ShowDataBand(DataBand dataBand, Int32 rowCount)
FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand, Int32 rowCount, Boolean keepFirstRow, Boolean keepLastRow) FastReport.Engine.ReportEngine.ShowGroupTree(GroupTreeItem root) FastReport.Engine.ReportEngine.ShowGroupTree(GroupTreeItem root)
FastReport.Engine.ReportEngine.RunGroup(GroupHeaderBand groupBand)
FastReport.Engine.ReportEngine.RunBands(BandCollection bands)
FastReport.Engine.ReportEngine.RunReportPage(ReportPage page)
FastReport.Engine.ReportEngine.RunReportPages()
FastReport.Engine.ReportEngine.RunReportPages(ReportPage page)
FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
FastReport.Report.Prepare(Boolean append)

此时你首先想到的就是转义,其实Fastreport提供了简单的方法

解决办法

变量标识符叫Brackets,它默认是[,],你可以把它替换成其它的"<,>", "<!,!>";但是任何其它的标识符也难免有作为文本的时候,此时你可以删除Brackets属性,那它就会直接把你的值作为变量来使用,而不会解析文本中的[]

参考资料:


fastreport显示带[] 方括号的文本或表达式
http://blog.wangshuai.app/2020-03-12-fastreport显示带[] 方括号的文本/
作者
王帅
发布于
2020年3月12日
许可协议