以编程方式设置水晶报告列的fontstyle?

如何以编程方式更改(设置)水晶报表列的字体(不想在设计时使用’格式编辑器’)? 什么是用于访问水晶报告详细信息部分的字段(列)的语法..?

提前致谢 。

在Crystal Report中运行时更改字体样式,字体大小和字体使用以下代码,这将正常运行:

您可以使用TextObject或FieldObject,具体取决于您的条件。使用FieldObject。

FieldObject MyText (FieldObject)Repotrdocumentobject.ReportDefinition.ReportObjects[i]; MyText.ApplyFont(new Font("Arial", 11f,FontStyle.Bold)); 

这里是Crystal Report中FieldObject的数量, 11f是字体大小

希望我刚刚汇总的代码片段有助于:

  ReportDocument rpt = new ReportDocument(); rpt.Load(@"C:\LT0001_COBDEN.rpt"); foreach (Area a in rpt.ReportDefinition.Areas) { string s = a.Name; } foreach (Section c in rpt.ReportDefinition.Sections) { string s = c.Name; } ObjectFormat of = rpt.ReportDefinition.Sections["GroupHeaderSection9"].ReportObjects["Text21"].ObjectFormat; TextObject to = (TextObject)rpt.ReportDefinition.Sections["GroupHeaderSection9"].ReportObjects["Text21"]; to.Color = Color.Red; crystalReportViewer1.ReportSource = rpt; crystalReportViewer1.Refresh(); 

您可以将CRAXDRT添加到引用中,然后像这样使用它

  CRAXDRT.Report report1 = new CRAXDRT.Report(); CRAXDRT.Application app1 = new CRAXDRT.Application(); stdole.IFontDisp myFont; report1 = app1.OpenReport("Test.rpt", OpenReportMethod.OpenReportByDefault); foreach (CRAXDRT.Section sec in report1.Sections) { for (int i = 1; i < sec.ReportObjects.Count + 1; i++) { object objMain, objChange; objMain = report1.Sections[sec.Name].ReportObjects[i]; try { objChange = objMain; CRAXDRT.TextObject to1 = (CRAXDRT.TextObject)objChange; myFont = to1.Font; myFont.Name = "Arial"; to1.Font = myFont; } catch (Exception) { try { objChange = objMain; CRAXDRT.FieldObject to1 = (CRAXDRT.FieldObject)objChange; myFont = to1.Font; myFont.Name = "Arial"; to1.Font = myFont; } catch (Exception){} } } }