彩票走势图

【Stimulsoft Reports.WinForms教程】在运行时使用交叉表创建报表

翻译|使用教程|编辑:王香|2018-08-24 10:44:48.000|阅读 593 次

概述:本文主要讲解Stimulsoft在运行时使用交叉表创建报表

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

【下载Stimulsoft Reports.Ultimate最新版本】

此示例显示如何使用代码中的交叉表组件创建报表,Сross-Tab是Business Analysis的工具,这是一个特殊组件,用于处理,分组和汇总数据源中的数据,结果以表格的形式呈现,要从代码创建交叉表,需要创建一个主要的交叉表组件:

#region CrossTab
 
Stimulsoft.Report.CrossTab.StiCrossTab crossTab1 = new Stimulsoft.Report.CrossTab.StiCrossTab();
crossTab1.ClientRectangle = new Stimulsoft.Base.Drawing.RectangleD(1.8, 4.6, 14.6, 13);
crossTab1.DataSourceName = "Categories";
crossTab1.Name = "CrossTab1";
 
...

交叉表是一组单元格,由行和列列表组成,此外,交叉表组件具有每行和每列的总单元格和总和,现在将行,列和总单元格添加到创建的Cross-Tab组件:

...
 
Stimulsoft.Report.CrossTab.StiCrossRowTotal crossTab1_RowTotal1 = new Stimulsoft.Report.CrossTab.StiCrossRowTotal();
crossTab1_RowTotal1.Guid = "416a93a6cbff4f24929c07006f5f4c21";
crossTab1_RowTotal1.Name = "CrossTab1_RowTotal1";
crossTab1_RowTotal1.Text.Value = "Total";
 
Stimulsoft.Report.CrossTab.StiCrossTitle crossTab1_Row1_Title = new Stimulsoft.Report.CrossTab.StiCrossTitle();
crossTab1_Row1_Title.Name = "CrossTab1_Row1_Title";
crossTab1_Row1_Title.TypeOfComponent = "Row:CrossTab1_Row1";
crossTab1_Row1_Title.Text.Value = "CategoryID";
 
Stimulsoft.Report.CrossTab.StiCrossColumnTotal crossTab1_ColTotal1 = new Stimulsoft.Report.CrossTab.StiCrossColumnTotal();
crossTab1_ColTotal1.Guid = "9e5a67edfe87448e96ebcf75e4ef19c4";
crossTab1_ColTotal1.Name = "CrossTab1_ColTotal1";
crossTab1_ColTotal1.Text.Value = "Total";
 
...

交叉表中显示的值和总计的值可能不同,可以使用DisplayValue.Value属性设置要在单元格中显示的值,可以使用Row1.Value.Value属性设置要汇总的值,还需要为左右交叉表列设置标题,定义交叉表的 Data columns数据列和标题:

...
 
Stimulsoft.Report.CrossTab.StiCrossTitle crossTab1_LeftTitle = new Stimulsoft.Report.CrossTab.StiCrossTitle();
crossTab1_LeftTitle.Guid = "a4a019be008042c9a4c4b604e041ceba";
crossTab1_LeftTitle.Name = "CrossTab1_LeftTitle";
crossTab1_LeftTitle.TypeOfComponent = "LeftTitle";
crossTab1_LeftTitle.Text.Value = "Categories";
 
Stimulsoft.Report.CrossTab.StiCrossRow crossTab1_Row1 = new Stimulsoft.Report.CrossTab.StiCrossRow();
crossTab1_Row1.Alias = "CategoryID";
crossTab1_Row1.Guid = "7f0d8b9785504d009e6afe47f70a74d3";
crossTab1_Row1.Name = "CrossTab1_Row1";
crossTab1_Row1.TotalGuid = "416a93a6cbff4f24929c07006f5f4c21";
crossTab1_Row1.DisplayValue.Value = "{Categories.CategoryID}";
crossTab1_Row1.Value.Value = "{Categories.CategoryID}";
 
Stimulsoft.Report.CrossTab.StiCrossColumn crossTab1_Column1 = new Stimulsoft.Report.CrossTab.StiCrossColumn();
crossTab1_Column1.Alias = "CategoryName";
crossTab1_Column1.Guid = "fc86b73eb9694091b62b55fce6041715";
crossTab1_Column1.Name = "CrossTab1_Column1";
crossTab1_Column1.TotalGuid = "9e5a67edfe87448e96ebcf75e4ef19c4";
crossTab1_Column1.DisplayValue.Value = "{Categories.CategoryName}";
crossTab1_Column1.Value.Value = "{Categories.CategoryName}";
 
Stimulsoft.Report.CrossTab.StiCrossSummary crossTab1_Sum1 = new Stimulsoft.Report.CrossTab.StiCrossSummary();
crossTab1_Sum1.Alias = "Description";
crossTab1_Sum1.Guid = "ec4c270655bf49a58766bf36a2b21c5c";
crossTab1_Sum1.Name = "CrossTab1_Sum1";
crossTab1_Sum1.Summary = Stimulsoft.Report.CrossTab.Core.StiSummaryType.None;
crossTab1_Sum1.Value.Value = "{Categories.Description}";
 
Stimulsoft.Report.CrossTab.StiCrossTitle crossTab1_RightTitle = new Stimulsoft.Report.CrossTab.StiCrossTitle();
crossTab1_RightTitle.Guid = "43929f3151c248b6b4e07b0a8ea44f93";
crossTab1_RightTitle.Name = "CrossTab1_RightTitle";
crossTab1_RightTitle.TypeOfComponent = "RightTitle";
crossTab1_RightTitle.Text.Value = "CategoryName";
 
#endregion

该的button1_Click方法读取XML数据,登记在新的报表,并增加了交叉表prevously创建:

private void button1_Click(object sender, EventArgs e)
{
    var data = new DataSet();
    data.ReadXmlSchema("..\\..\\Data\\Demo.xsd");
    data.ReadXml("..\\..\\Data\\Demo.xml");
 
    var report = new StiReport();
    report.RegData("Demo", data);
    report.Dictionary.Synchronize();
 
    #region CrossTab
    ...
    #endregion
 
    report.Pages[0].Components.Add(crossTab1);
    crossTab1.Components.AddRange(new Stimulsoft.Report.Components.StiComponent[] {
                crossTab1_RowTotal1,
                crossTab1_Row1_Title,
                crossTab1_ColTotal1,
                crossTab1_LeftTitle,
                crossTab1_Row1,
                crossTab1_Column1,
                crossTab1_Sum1,
                crossTab1_RightTitle});
 
    report.Show();
}

示例代码的结果如下图所示:

Stimulsoft


标签:报表StimulsoftWinForms

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@cahobeh.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP