Post Author: KonRi
CA Forum: .NET
I want to change all fonts in my rpt files from Arial to Tahoma. I have:
ReportDocument report;
raport.Load(fInfos[i].FullName);
if (report.IsLoaded) ChangeFont(report, path);
... private void ChangeFont(ReportDocument oReport, string path) { foreach (CrystalDecisions.CrystalReports.Engine.Section crSection in oReport.ReportDefinition.Sections) { foreach (CrystalDecisions.CrystalReports.Engine.ReportObject crObject in crSection.ReportObjects) { FontStyle fStyle = FontStyle.Regular; if (crObject.Kind == ReportObjectKind.TextObject) { CrystalDecisions.CrystalReports.Engine.TextObject text = (CrystalDecisions.CrystalReports.Engine.TextObject)crObject; if(text!=null) { if (text.Font.Bold) fStyle = fStyle | FontStyle.Bold; if (text.Font.Italic) fStyle = fStyle | FontStyle.Italic; if (text.Font.Underline) fStyle = fStyle | FontStyle.Underline; if (text.Font.Strikeout) fStyle = fStyle | FontStyle.Strikeout; text.ApplyFont(new Font("Tahoma", text.Font.Size,fStyle)); } } else if (crObject.Kind == ReportObjectKind.FieldObject) { ... the same } else if (crObject.Kind == ReportObjectKind.FieldHeadingObject) { ... the same } else if (crObject.Kind == ReportObjectKind.SubreportObject) { CrystalDecisions.CrystalReports.Engine.SubreportObject crSubReport = (CrystalDecisions.CrystalReports.Engine.SubreportObject)crObject; ReportDocument crSubDoc = crSubReport.OpenSubreport(crSubReport.SubreportName); ChangeFont(crSubDoc,path); } } } if (!oReport.IsSubreport) oReport.SaveAs(path); }
This works fine but when TextObject has Embedded Fields those Fields aren't change and still have Arial font.My question is: how to change font in whole rpt file, including Embedded Fields?? RegardsKonRi