设置一个水晶报表编程的列fontstyle?(set fontstyle of a column o

2019-09-17 13:55发布

如何-CHANGE对于Crystal报表编程的列(组)字体(不想使用在设计时“格式编辑器”)? 最新用于访问晶体报告的细节部分的字段(列)的语法..?

提前致谢 。

Answer 1:

在水晶报表使用运行时更改字体样式,字体大小和字体下面的代码,这将正常运行:

您可以使用TextObject或FieldObject根据您的condition.here正在使用FieldObject。

 FieldObject MyText (FieldObject)Repotrdocumentobject.ReportDefinition.ReportObjects[i];

MyText.ApplyFont(new Font("Arial", 11f,FontStyle.Bold));

在这里, 是FieldObject的水晶报表数量和11F的字体大小



Answer 2:

但愿这段代码我只是把一起将帮助:

        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();


Answer 3:

您可以添加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){}
                }
            }

        }


文章来源: set fontstyle of a column of a crystal report programatically?