在 Crystal 报告中,我想相应地设置字段的对齐方式。我怎样才能在运行时做同样的事情?
太好了。这是有效的。谢谢。我做了同样的事情,代码如下所示。
var fo = rpt.ReportDefinition.ReportObjects["InvoiceComment"];
fo.ObjectFormat.HorizontalAlignment = Alignment.LeftAlign;
if (ds.Tables[0].Rows[0].ItemArray[19].ToString() == "Right")
fo.ObjectFormat.HorizontalAlignment = Alignment.RightAlign;
else
if (ds.Tables[0].Rows[0].ItemArray[19].ToString() == "Center")
fo.ObjectFormat.HorizontalAlignment = Alignment.HorizontalCenterAlign;`
但我现在正在经历另一个问题。
FieldObject fo = rpt.ReportDefinition.ReportObjects["InvoiceComment"] as FieldObject;
或者
var fo = rpt.ReportDefinition.ReportObjects["InvCom"];
显示相同的错误“索引超出数组范围”。
如果我使用另一个代码而不是它的工作原理。
FieldObject fo = rpt.ReportDefinition.ReportObjects[35] as FieldObject;
如何发生这种情况。
提前致谢。
最佳答案
要更改字段的水平对齐方式,请遵循以下提到的步骤:
1) 右键单击该字段。
2) 单击格式字段选项。
3) 选择通用选项卡。
4) 点击水平对齐前面的公式编辑器,添加需要的设置。
5) 以下是可用的对齐常数:
不变
crDefaultHorAligned
crLeftAligned
crRightAligned
crCenteredHorizontally
crJustified
根据您的标准使用它。
关于crystal-reports - 如何在运行时更改 Crystal 报表中报表字段的对齐方式,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11260447/