2

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

提前致谢 。

4

3 回答 3

3

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

您可以根据您的条件使用 TextObject 或 FieldObject。这里使用的是 FieldObject。

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

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

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

于 2015-04-23T06:29:23.613 回答
0

希望我刚刚拼凑的这段代码片段会有所帮助:

        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();
于 2012-05-28T10:22:36.970 回答
0

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

        }
于 2013-10-06T10:54:00.547 回答