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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • [渝粤教育] 徐州工业职业技术学院 橡胶原材料 参考 资料「建议收藏」

    [渝粤教育] 徐州工业职业技术学院 橡胶原材料 参考 资料「建议收藏」教育-橡胶原材料-章节资料考试资料-徐州工业职业技术学院【】课程认知随堂测验1、【多选题】下列制品可采用橡胶材料制作的是。A、轮胎B、鞋子底C、输送带D、婴儿奶嘴参考资料【】2、【多选题】硫化体系主要包括。A、硫化剂B、促进剂C、活性剂D、防焦剂参考资料【】3、【判断题】橡胶是一种材料,它在大的形变下能迅速而有力恢复其形变,能够被改性(硫化)。A、正确B、错误参考资料【】4、【判断题】生胶是一种高弹性高聚物材料,是制造橡胶制品的基础材料,一

    2022年10月2日
    4
  • 电商招聘那些事——揭秘万达电商(7)

    电商招聘那些事——揭秘万达电商(7)

    2022年1月1日
    315
  • tableau旭日图_Echart

    tableau旭日图_Echart效果图源代码ECharts//基于准备好的dom,初始化echarts实例varmyChart=echarts.init(document.getElementById(‘main’));varoption;option={silent:true,series:{radius:[‘15%’,’80%’],type:’sunburst’,sort:null,highligh…

    2022年9月25日
    3
  • Jmeter刷csdn博客访问量

    Jmeter刷csdn博客访问量使用Jmeter刷csdn博客访问量首先我们先分析一下该网站的接口情况服务器ip为blog.csdn.net协议为https接口url为/qq_38776582请求方法为GET打开jmeter,分别将参数填写进去:copy请求头参数,填写在HTTP信息头管理器:接下来是最关键的一步,分析博客页面数据:添加边界提取器,提取数据:接下来我们把提取到数据添加到接口中:脚本总…

    2022年6月18日
    30
  • Android物联网应用程序开发(智慧城市)—— 火焰监控界面开发

    Android物联网应用程序开发(智慧城市)—— 火焰监控界面开发效果:布局代码:<?xmlversion=”1.0″encoding=”utf-8″?><RelativeLayoutxmlns:android=”http://schemas.android.com/apk/res/android”xmlns:app=”http://schemas.android.com/apk/res-auto”xmlns:tools=”http://schemas.android.com/tools”androi.

    2022年6月21日
    37
  • 缺陷报告编写规范[通俗易懂]

    缺陷报告编写规范[通俗易懂]引言 软件缺陷定义  软件缺陷(Defect):又叫做Bug。即为计算机软件、程序、web应用中存在的某种不符合正常运行的功能问题。也是错误、隐藏,让用户不满意的功能缺陷。从产品内部看,缺陷是软件产品开发或维护过程中存在的错误、毛病等各种问题;从产品外部看,缺陷是系统所需要实现的某种功能的失效或违背。 缺陷报告定义  缺陷报告把测试的过程和结果写成文档,并对发现的问题和缺陷进行分析,为…

    2026年1月19日
    3

发表回复

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

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