如何使用代码动态设置水晶报表中的文本,字段等对象
1个回答
展开全部
首先,你必须要声明一个OBJECT变量(eg. TextObject, FieldObject, ......),当然不是一般的对象,而是:
Dim xObject As CrystalDecisions.CrystalReports.Engine.FieldObject(字段)
Dim xObject As CrystalDecisions.CrystalReports.Engine.TextObject(文本)
Dim xObject As CrystalDecisions.CrystalReports.Engine.LineObject(线条)
Dim xObject As CrystalDecisions.CrystalReports.Engine.BoxObject(矩形框)
......
其次,你必须将水晶报表的真实对象赋值给它,例如:
xObject = crReport.ReportDefinition.ReportObjects.Item("FieldObjectName")
xObject = crReport.ReportDefinition.ReportObjects.Item("TextObjectName")
xObject = crReport.ReportDefinition.ReportObjects.Item("LineObjectName")
xObject = crReport.ReportDefinition.ReportObjects.Item("BoxObjectName")
......
然后,你就可以调用它的各种属性和方法了:
对于FieldObject,你可以:
1.设置数值字段的小数点位数:
xObject.FieldFormat.NumericFormat.DecimalPlaces = 4
2.设置布尔字段的输出类型:
xObject.FieldFormat.BooleanFormat.OutputType =CrystalDecisions.Shared.BooleanOutputType.YesOrNo
3.设置其他格式如(CommonFormat,DateTimeFormat,DateFormat,TimeFormat)
对于TextObject,你可以:
1.改变文本:
xObject.Text = "嘿嘿"
2.改变字体:
xObject.ApplyFont(New Font("宋体", 10.0!))
3.设置颜色:
xObject.Color = Color.Red
3.隐藏显示:
xObject.ObjectFormat.EnableSuppress = True
对于LineObject,你可以:
1.设置线条风格:
xObject.LineStyle = CrystalDecisions.Shared.LineStyle.DotLine
2.设置线条颜色:
xObject.LineColor = Color.Blue
3.设置线条宽度:
xObject.LineThickness = 3
4.设置其他格式(如:位置(top,left,right,bottom),边框等)
对于BoxObject,你可以:
1.设置填充颜色:
xObject.FillColor = Color.Brown
2.设置线条风格:
xObject.LineStyle = CrystalDecisions.Shared.LineStyle.DotLine
3.设置线条颜色:
xObject.LineColor = Color.Blue
4.设置线条宽度:
xObject.LineThickness = 3
5.设置其他格式(如:位置(top,left,right,bottom),边框等)
//C#
CrystalDecisions.CrystalReports.Engine.TextObject xObject;
xObject = (CrystalDecisions.CrystalReports.Engine.TextObject)CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text1"];
xObject.Text="条件";
你可以试试finereport,比这个用起来方便,网上教程也多
Dim xObject As CrystalDecisions.CrystalReports.Engine.FieldObject(字段)
Dim xObject As CrystalDecisions.CrystalReports.Engine.TextObject(文本)
Dim xObject As CrystalDecisions.CrystalReports.Engine.LineObject(线条)
Dim xObject As CrystalDecisions.CrystalReports.Engine.BoxObject(矩形框)
......
其次,你必须将水晶报表的真实对象赋值给它,例如:
xObject = crReport.ReportDefinition.ReportObjects.Item("FieldObjectName")
xObject = crReport.ReportDefinition.ReportObjects.Item("TextObjectName")
xObject = crReport.ReportDefinition.ReportObjects.Item("LineObjectName")
xObject = crReport.ReportDefinition.ReportObjects.Item("BoxObjectName")
......
然后,你就可以调用它的各种属性和方法了:
对于FieldObject,你可以:
1.设置数值字段的小数点位数:
xObject.FieldFormat.NumericFormat.DecimalPlaces = 4
2.设置布尔字段的输出类型:
xObject.FieldFormat.BooleanFormat.OutputType =CrystalDecisions.Shared.BooleanOutputType.YesOrNo
3.设置其他格式如(CommonFormat,DateTimeFormat,DateFormat,TimeFormat)
对于TextObject,你可以:
1.改变文本:
xObject.Text = "嘿嘿"
2.改变字体:
xObject.ApplyFont(New Font("宋体", 10.0!))
3.设置颜色:
xObject.Color = Color.Red
3.隐藏显示:
xObject.ObjectFormat.EnableSuppress = True
对于LineObject,你可以:
1.设置线条风格:
xObject.LineStyle = CrystalDecisions.Shared.LineStyle.DotLine
2.设置线条颜色:
xObject.LineColor = Color.Blue
3.设置线条宽度:
xObject.LineThickness = 3
4.设置其他格式(如:位置(top,left,right,bottom),边框等)
对于BoxObject,你可以:
1.设置填充颜色:
xObject.FillColor = Color.Brown
2.设置线条风格:
xObject.LineStyle = CrystalDecisions.Shared.LineStyle.DotLine
3.设置线条颜色:
xObject.LineColor = Color.Blue
4.设置线条宽度:
xObject.LineThickness = 3
5.设置其他格式(如:位置(top,left,right,bottom),边框等)
//C#
CrystalDecisions.CrystalReports.Engine.TextObject xObject;
xObject = (CrystalDecisions.CrystalReports.Engine.TextObject)CrystalReportSource1.ReportDocument.ReportDefinition.ReportObjects["Text1"];
xObject.Text="条件";
你可以试试finereport,比这个用起来方便,网上教程也多
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询