【Stimulsoft Reports.Net教程】运行时创建报表

下载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 xmlns="http://www.w3.org/1999/xhtml">
<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(@"Data\Demo.xsd"));
    data.ReadXml(Server.MapPath(@"Data\Demo.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

查看原文,下载示例

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值