Skip to content

Latest commit

History

History
99 lines (94 loc) · 3.07 KB

File metadata and controls

99 lines (94 loc) · 3.07 KB

Creating a report by using code

Let us consider how to create a report in code.

Reportreport=newReport();// register the "Products" tablereport.RegisterData(dataSet1.Tables["Products"],"Products");// enable it to use in a reportreport.GetDataSource("Products").Enabled=true;// create A4 page with all margins set to 1cmReportPagepage1=newReportPage();page1.Name="Page1";report.Pages.Add(page1);// create ReportTitle bandpage1.ReportTitle=newReportTitleBand();page1.ReportTitle.Name="ReportTitle1";// set its height to 1.5cmpage1.ReportTitle.Height=Units.Centimeters*1.5f;// create group headerGroupHeaderBandgroup1=newGroupHeaderBand();group1.Name="GroupHeader1";group1.Height=Units.Centimeters*1;// set group conditiongroup1.Condition="[Products.ProductName].Substring(0, 1)";// add group to the page.Bands collectionpage1.Bands.Add(group1);// create group footergroup1.GroupFooter=newGroupFooterBand();group1.GroupFooter.Name="GroupFooter1";group1.GroupFooter.Height=Units.Centimeters*1;// create DataBandDataBanddata1=newDataBand();data1.Name="Data1";data1.Height=Units.Centimeters*0.5f;// set data sourcedata1.DataSource=report.GetDataSource("Products");// connect databand to a groupgroup1.Data=data1;// create "Text" objects// report titleTextObjecttext1=newTextObject();text1.Name="Text1";// set boundstext1.Bounds=newRectangleF(0,0,Units.Centimeters*19,Units.Centimeters*1);// set texttext1.Text="PRODUCTS";// set appearancetext1.HorzAlign=HorzAlign.Center;text1.Font=newFont("Tahoma",14,FontStyle.Bold);// add it to ReportTitlepage1.ReportTitle.Objects.Add(text1);// groupTextObjecttext2=newTextObject();text2.Name="Text2";text2.Bounds=newRectangleF(0,0,Units.Centimeters*2,Units.Centimeters*1);text2.Text="[[Products.ProductName].Substring(0, 1)]";text2.Font=newFont("Tahoma",10,FontStyle.Bold);// add it to GroupHeadergroup1.Objects.Add(text2);// data bandTextObjecttext3=newTextObject();text3.Name="Text3";text3.Bounds=newRectangleF(0,0,Units.Centimeters*10,Units.Centimeters*0.5f);text3.Text="[Products.ProductName]";text3.Font=newFont("Tahoma",8);// add it to DataBanddata1.Objects.Add(text3);// group footerTextObjecttext4=newTextObject();text4.Name="Text4";text4.Bounds=newRectangleF(0,0,Units.Centimeters*10,Units.Centimeters*0.5f);text4.Text="Count: [CountOfProducts]";text4.Font=newFont("Tahoma",8,FontStyle.Bold);// add it to GroupFootergroup1.GroupFooter.Objects.Add(text4);// add a totalTotalgroupTotal=newTotal();groupTotal.Name="CountOfProducts";groupTotal.TotalType=TotalType.Count;groupTotal.Evaluator=data1;groupTotal.PrintOn=group1.Footer;// add it to report totalsreport.Dictionary.Totals.Add(groupTotal);// run the reportreport.Prepare();
...

The prepared report looks as follows:


Report Template File Structure | Top Page | Using the Report