此示例项目显示了在运行时创建Web报表的可能性。您只需要Web查看器即可显示创建的报表,并最少创建报表项目的代码。
下载Stimulsoft Reports.Net最新版本
要添加Web查看器,您可以使用以下ASPX页面。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="Runtime_Report_Creation.Report" %><%@ Register Assembly="Stimulsoft.Report.Web" Namespace="Stimulsoft.Report.Web" TagPrefix="cc1" %><!DOCTYPE html><html ><head runat="server"> <title>Runtime Report Creation</title></head><body> <form id="form1" runat="server"> <cc1:StiWebViewer ID="StiWebViewer1" runat="server" /> </form></body></html>
所有必要的操作都可以在网页的Page_Load事件中完成。首先,创建新的报表对象,读取数据并将其连接到报表字典。
protected void Page_Load(object sender, EventArgs e){ DataSet data = new DataSet(); data.ReadXmlSchema(Server.MapPath(@"DataDemo.xsd")); data.ReadXml(Server.MapPath(@"DataDemo.xml")); StiReport report = new StiReport(); report.RegData(data); //Fill dictionary report.Dictionary.Synchronize();...
然后我们需要创建报表组件。首先,使用将显示标题的Text组件将Header Band添加到报表页面。
... StiPage page = report.Pages[0]; //Create HeaderBand StiHeaderBand headerBand = new StiHeaderBand(); headerBand.Height = 0.5; headerBand.Name = "HeaderBand"; page.Components.Add(headerBand); //Create text on header StiText headerText = new StiText(new RectangleD(0, 0, 5, 0.5)); headerText.Text = "CompanyName"; headerText.HorAlignment = StiTextHorAlignment.Center; headerText.Name = "HeaderText"; headerText.Brush = new StiSolidBrush(System.Drawing.Color.LightGreen); headerBand.Components.Add(headerText);...
接下来,使用添加表达式的Text组件添加数据带。此表达式组合了客户数据源中的行号和CompanyName数据列。
... //Create Databand StiDataBand dataBand = new StiDataBand(); dataBand.DataSourceName = "Customers"; dataBand.Height = 0.5; dataBand.Name = "DataBand"; page.Components.Add(dataBand); //Create text StiText dataText = new StiText(new RectangleD(0, 0, 5, 0.5)); dataText.Text = "{Line}.{Customers.CompanyName}"; dataText.Name = "DataText"; dataBand.Components.Add(dataText);...
最后,使用Text组件添加页脚页带,该组件在页面底部显示文本。最后一个操作是将创建的报表分配给WebViewer,WebViewer将自动构建和显示它。
... //Create FooterBand StiFooterBand footerBand = new StiFooterBand(); footerBand.Height = 0.5; footerBand.Name = "FooterBand"; page.Components.Add(footerBand); //Create text on footer StiText footerText = new StiText(new RectangleD(0, 0, 5, 0.5)); footerText.Text = "Count - {Count()}"; footerText.HorAlignment = StiTextHorAlignment.Right; footerText.Name = "FooterText"; footerText.Brush = new StiSolidBrush(System.Drawing.Color.LightGreen); footerBand.Components.Add(footerText); StiWebViewer1.Report = report;}
示例代码的结果如下图所示:
下载示例
购买Stimulsoft正版授权,请点击“咨询在线客服”哟!
标签:报表解决方案报表.NET报表控件报表设计stimulsoft report .netStimulsoft
来源:慧都
声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!