2012-05-28 61 views

回答

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

非常感謝先生。 Lee – user1418842

+0

by god grace,經過艱苦的努力,我可以找到答案...在這裏發佈,希望這可以幫助其他人,, 以編程方式設置列的字體(動態):: .... ....... FieldObject Fobj =(FieldObject)place_your_report_obj.ReportDefinition.ReportObjects [「Columnobj」]; Fobj.ApplyFont(new Font(「arial」,15F)); 注意:右鍵單擊欄的細節部分選擇formateobject比你會發現objectname對應的選定列 ........... – user1418842

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){} 
       } 
      } 

     } 
+0

請不要發佈完全相同的答案多個問題:它是不適合所有人或問題是應該標記/關閉的重複。 – kleopatra

3

更改字體樣式,字體大小,和字體在運行時Crystal Report使用以下代碼,這將正常運行:

您可以使用TextObject或Field對象取決於你的條件。我在使用FieldObject。

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

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

這裏是水晶報表FieldObject的數量和11F是字體大小