Creating Report at Runtime
Our sample projects and report templates can help you learn the basics of working with our products.A whole report — pages, bands and components — can be assembled in code, without a pre-designed
Register the data. Load a data source and synchronize the dictionary so fields become available to the report:
How it works. The band tree you build in code is exactly what the designer would produce, so the report renders, prints and exports the same as a template-based one.
.mrt template.Register the data. Load a data source and synchronize the dictionary so fields become available to the report:
var report = new StiReport();
var dataSet = StiJsonToDataSetConverterV2.GetDataSetFromFile(@"Data\Demo.json");
report.RegData(dataSet);
report.Dictionary.Synchronize();Build the page structure. Add bands to the page and text components to the bands. Expressions in braces are evaluated per row:var page = report.Pages[0];
var headerBand = new StiHeaderBand { Height = 0.5, Name = "HeaderBand" };
page.Components.Add(headerBand);
headerBand.Components.Add(new StiText(new RectangleD(0, 0, 5, 0.5)) { Text = "CompanyName" });
var dataBand = new StiDataBand { DataSourceName = "Customers", Height = 0.5, Name = "DataBand" };
page.Components.Add(dataBand);
dataBand.Components.Add(new StiText(new RectangleD(0, 0, 5, 0.5)) { Text = "{Line}.{Customers.CompanyName}" });Show the result.report.Show();RegData+Dictionary.Synchronize()— register a dataset and generate matching data-source fields.StiHeaderBand/StiDataBand/StiFooterBand— the row-repeating structure of the report.- Text expressions such as
{Customers.CompanyName}and{Count()}are resolved against the current row.
How it works. The band tree you build in code is exactly what the designer would produce, so the report renders, prints and exports the same as a template-based one.