Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」一、编译环境VisualStudio2017,Win764位,Stimulsoft版本2016.1.0.0。二、报表环境的汉化(代码实现)安装完Stimulsoft后,在路径下C:\ProgramFiles(x86)\StimulsoftReports.Net2016.1Trial\Localization中会发现很多xml文件,这些文…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

一、编译环境

        Visual Studio 2017,Win7 64位,Stimulsoft版本 2016.1.0.0。

二、报表环境的汉化(代码实现)

       安装完Stimulsoft后,在路径下 C:\Program Files (x86)\Stimulsoft Reports.Net 2016.1 Trial\Localization中会发现很多xml文件,这些文件就是语言文件,其中  zh-CHS.xml  是简体中文的文件,zh-CHT.xml是繁体中文的文件。可以把语言文件拿出来跟着项目走,放在项目的一个文件夹中。然后通过代码加载这个文件。

Stimulsoft.Base.Localization.StiLocalization.Load(Application.StartupPath + "\\zh-CHS");

三、创建一个报表对象并添加一个新页,绑定数据集

public StiReport MyReport = new StiReport();
public DataSet fcgb;
fcgb = DBHelper.ExecuteAllQuerySql("select FormNo,ProdCode,ProdName,PUnitAmt,Unit,Price from FTHB");
fcgb.Tables[0].TableName = "tb_B";
MyReport.RegData("tb_B", fcgb);
StiPage page = MyReport.Pages[0];

其中DBHelper是自己写的数据库操作类,这个类可以自己按照实际需求来写。

四、设置报表显示内容及格式,因为是我自己做记录自己看,直接上代码

//创建分组头
            StiGroupHeaderBand MyGroupReportHeaderBand_1 = new StiGroupHeaderBand();
            MyGroupReportHeaderBand_1.Height = 0.5;
            MyGroupReportHeaderBand_1.Name = "MyReportGHeaderBand_1";
            MyGroupReportHeaderBand_1.KeepGroupHeaderTogether = true;
            MyGroupReportHeaderBand_1.KeepGroupTogether = true;
            //再有条件就往后接着添加"{tb_B.DepCode}{别的条件}",这是按FormNo分组
            MyGroupReportHeaderBand_1.Condition = new Stimulsoft.Report.Components.StiGroupConditionExpression("{tb_B.FormNo}");
            page.Components.Add(MyGroupReportHeaderBand_1);



//创建显示数据的部分
            StiDataBand MyReportDataBody = new StiDataBand();
            MyReportDataBody.DataSourceName = "tb_B";//要跟reageData时起的别字一样
            MyReportDataBody.Height = 1;
            MyReportDataBody.Name = "MyReportDataBody";
            page.Components.Add(MyReportDataBody);

//创建页脚部分
            StiGroupFooterBand footerBand = new StiGroupFooterBand();
            footerBand.Height = 0.5;
            footerBand.Name = "G_FooterBand_1";
            page.Components.Add(footerBand);


//往分组头部分添加内容,可用循环
//foreach (DataColumn dataColumn in fcgb.Tables[0].Columns)
                StiText headerTextB = new StiText(new RectangleD(pos, 0, columnWidth,     0.5));
                headerTextB.Text.Value = dataColumn.Caption;
                headerTextB.HorAlignment = StiTextHorAlignment.Center;
                headerTextB.Name = "BodyClum" + nameIndex.ToString();
                headerTextB.Brush = new StiSolidBrush(Color.LightGreen);

                headerTextB.Border.Side = StiBorderSides.All;
                MyGroupReportHeaderBand_1.Components.Add(headerTextB);






//往页脚加平均值
//MoneyToUpper是一个金额转人民币大写的函数,网上有
 StiText headerTextFooter = new StiText(new RectangleD(pos, 0, columnWidth, 0.5));
                    headerTextFooter.Text.Value = "平均值: {MoneyToUpper(Round(Avg(tb_B." + ClumName + "),2))}"; ;
                    headerTextFooter.HorAlignment = StiTextHorAlignment.Center;
                    headerTextFooter.Name = "BodyOPriceAvg";
                    headerTextFooter.Brush = new StiSolidBrush(Color.LightGreen);
                    headerTextFooter.Border.Side = StiBorderSides.All;
                    footerBand.Components.Add(headerTextFooter);





//这是设置不同行的颜色不同
                StiCondition condition = new StiCondition();
                condition.BackColor = Color.CornflowerBlue;
                condition.TextColor = Color.Black;
                condition.Expression = "(Line & 1) == 1";
                condition.Item = StiFilterItem.Expression;





//往表体部分写内容,可用循环
 StiText dataText = new StiText(new RectangleD(pos, 0, columnWidth, 1));   

                dataText.Name = "BodyDataText" + nameIndex.ToString();
                dataText.Text.Value = "{tb_B." + ClumName + "}";
                dataText.Border.Side = StiBorderSides.All;
                dataText.WordWrap = true;//自动折行
                dataText.CanGrow = true;//适应折行大小
                dataText.Conditions.Add(condition);//设置奇偶行颜色
                MyReportDataBody.Components.Add(dataText);


五、关于自定义的外部函数

    因为我没找到如何使报表调用外部函数,但是他可以再报表中的代码编写页面中自己定义函数。报表保存后用记事本打开,发现时xml格式的,而自己添加的函数脚本是在Script节点下的。

<Script>
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using Stimulsoft.Controls;
using Stimulsoft.Base.Drawing;
using Stimulsoft.Report;
using Stimulsoft.Report.Dialogs;
using Stimulsoft.Report.Components;

namespace Reports
{
    public class Report : Stimulsoft.Report.StiReport
    {
        public Report()        {
            this.InitializeComponent();
        }

        #region StiReport Designer generated code - do not modify
		#endregion StiReport Designer generated code - do not modify
    }
}
</Script>

所以我通过报表自带的获取script的方法,吧这些脚本取出来保存成字符串,然后定位到#region,在这前面插入要写的函数。

            string script = MyReport.Script;
            MyReport.Script = script.Insert(script.LastIndexOf("#region"), RFunStr());
            MyReport.Dictionary.Synchronize();
            MyReport.Save("Report.mrt");
            MyReport.Dispose();
            MyReport = null;

然后再赋值回去,再保存报表。

 

六、设计界面

     我新建了一个窗体,在里面放了一个Stimulsoft.Report.Design.StiRibbonDesignerControl对象,这个是从工具栏跟拖动按钮似的拖上去的。

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

控件加载报表对象的方法

this.stiRibbonDesignerControl1.Report = this.MyReport;

MyReport要重新加载报表文件,注册数据集

            MyReport = new StiReport();
            MyReport.Load("Reportstream.mrt");
            MyReport.RegData("tbB", fcgb);

七、预览界面

新建立了一个窗体,里面放了一个预览控件

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

预览控件预览报表的方法

            this.MyReport.Render();
            this.stiRibbonViewerControl1.Report = this.MyReport;

同样的,MyReport要重新加载报表文件,注册数据集

八,运行效果

 设计

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

预览

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

 

九、拿到没安装报表的电脑上正常运行需要的动态库

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

 

添加:

2019/3/12  打印时合并相同值的单元格

StiText dataText = new StiText();
dataText.ProcessingDuplicates = StiProcessingDuplicatesType.Merge;

靠在一起的能合并,不靠在一起的没法合并

Stimulsoft.Report的代码实现功能自学整理(一)「建议收藏」

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/158805.html原文链接:https://javaforall.net

(0)
上一篇 2022年7月26日 下午7:00
下一篇 2022年7月26日 下午7:16


相关推荐

  • hadoop namenode的功能

    hadoop namenode的功能hadoop namenode的功能

    2022年4月23日
    64
  • PLSQL Developer(安装、连接、汉化、注册图文教程)[通俗易懂]

    PLSQL Developer(安装、连接、汉化、注册图文教程)[通俗易懂]PLSQLDeveloper(安装、连接、汉化、注册图文教程)一、安装PLSQLDeveloper—版本11.0.5.1790(64bit)1、解压oracle客户端到d盘某个目录。2、安装PLSQLDeveloper开发工具,点击plsqlev1105.exe,开始进入安装界面,点击Next。3、同意协议,Next。

    2022年6月22日
    276
  • QT,QVector 基本用法,遍历[实例讲解]

    QT,QVector 基本用法,遍历[实例讲解]本文讲述了 QVector 的基本使用方法 使初学者轻松上手 本文结合代码示例 能够使阅读者更加深刻的学习 QVector 的是用用方法

    2026年3月19日
    3
  • 《深入浅出WPF》学习笔记之一

    《深入浅出WPF》学习笔记之一发现一本对 WPF 讲解的十分透彻的教程 是刘铁猛大大的 深入浅出 WPF 的讲解视频 讲得很清晰 视频地址 nbsp 深入浅出 WPF 视频列表以下是新建 WPF 项目课程的笔记 c 编译器 MicroSoftwin c 编译命令 csc 生成 WPF 项目时的初始化文件 App xaml App xmal csStartupUri Main

    2026年3月17日
    1
  • 遍历map的四种方法

    遍历map的四种方法 Map.entrySet()这个方法返回的是一个Set<Map.Entry<K,V>>,Map.Entry是Map中的一个接口,他的用途是表示一个映射项(里面有Key和Value),而Set<Map.Entry<K,V>>表示一个映射项的Set。Map.Entry里有相应的getKey和getValue方法,即JavaBean,让我们能够从一个项中取出…

    2026年2月10日
    5
  • batchnormalization是什么意思_batchnorm层参数个数

    batchnormalization是什么意思_batchnorm层参数个数1.背景本篇博文主要讲解2015年深度学习领域,非常值得学习的一篇文献:《BatchNormalization:AcceleratingDeepNetworkTrainingbyReducingInternalCovariateShift》,这个算法目前已经被大量的应用,最新的文献算法很多都会引用这个算法,进行网络训练,可见其强大之处非同一般啊。近年来深度学习捷报连连…

    2022年10月14日
    4

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号