SAP Knowledge Base Article - Public

1306531 - How to add a text object to a report using the Crystal Reports .NET inproc RAS SDK

Symptom

How to add a text object to a report using the Crystal Reports .NET inproc RAS SDK?

Reproducing the Issue

  • Crystal Reports XI Release 2 Service Pack 2 and later 
  • C#
  • Resolution

    sample code:


               using CrystalDecisions.CrystalReports.Engine;
               using CrystalDecisions.ReportAppServer.ClientDoc;
                          

                //CR Declarations
                ReportDocument                                                                                                            m_boReportDocument;
                ISCDReportClientDocument                                                                                        m_boReportClientDocument;
            
               CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject                        m_boReportObject;
               CrystalDecisions.ReportAppServer.ReportDefModel.ReportObject                        m_boReportObjectModified;

               CrystalDecisions.ReportAppServer.ReportDefModel.Section                                m_boSection;
               CrystalDecisions.ReportAppServer.ReportDefModel.TextObject                           m_boTextObject;
               CrystalDecisions.ReportAppServer.ReportDefModel.Paragraphs                          m_boParagraphs;
               CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph                            m_boParagraph;
               CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphElements           m_boParagraphElements;
               CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement      m_boParagraphTextElement;
               CrystalDecisions.ReportAppServer.ReportDefModel.FontColor                             m_boFontColor;
               CrystalDecisions.ReportAppServer.ReportDefModel.Font                                      m_boFont;
     

                //create a new ReportDocument
                m_boReportDocument = new ReportDocument();

                //load the RPT file
                m_boReportDocument.Load("..\\..\\DummyReport.rpt");

                //access the ReportClientDocument in the ReportDocument (EROM bridge)
                m_boReportClientDocument = m_boReportDocument.ReportClientDocument;

                //first determine which area and section to add the text field to - in this case the ReportHeaderArea first's section
                m_boSection = m_boReportClientDocument.ReportDefController.ReportDefinition.ReportHeaderArea.Sections[0];
             
                //create the textobject
                m_boTextObject = new CrystalDecisions.ReportAppServer.ReportDefModel.TextObject();
             
                //create the paragraph elements for the textobject 
                m_boParagraphs = new CrystalDecisions.ReportAppServer.ReportDefModel.Paragraphs();
                m_boParagraph = new CrystalDecisions.ReportAppServer.ReportDefModel.Paragraph();
                m_boParagraphElements = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphElements();
                m_boParagraphTextElement = new CrystalDecisions.ReportAppServer.ReportDefModel.ParagraphTextElement();
             
                //set the text value for the text field
                m_boParagraphTextElement.Text = "This is the added text field in the reportheader";
                m_boParagraphTextElement.Kind = CrystalDecisions.ReportAppServer.ReportDefModel.CrParagraphElementKindEnum.crParagraphElementKindText;
             
                //fix some wierd defaults and behavior by explicitly setting default font
                m_boFontColor = new CrystalDecisions.ReportAppServer.ReportDefModel.FontColor();
                m_boFont = new CrystalDecisions.ReportAppServer.ReportDefModel.Font();
                m_boFont.Bold = true;
                m_boFont.Name = "Arial";
                m_boFontColor.Font = m_boFont;
                m_boParagraphTextElement.FontColor = m_boFontColor;
                m_boParagraphElements.Add(m_boParagraphTextElement);
                m_boParagraph.ParagraphElements = m_boParagraphElements;
                m_boParagraphs.Add(m_boParagraph);
                m_boTextObject.Paragraphs = m_boParagraphs;
             
                //now add it to the section
                m_boTextObject.Left = 2000;
                m_boTextObject.Top = 1;
                m_boTextObject.Width = 5000;
                m_boTextObject.Height = 226;
                m_boReportClientDocument.ReportDefController.ReportObjectController.Add(m_boTextObject, m_boSection, -1);

                //display in reportviewer
                crystalReportViewer1.ReportSource = m_boReportDocument;


    Keywords

    How add textobject report Crystal Reports .NET inproc RAS SDK , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

    Product

    SAP Crystal Reports XI R2