Stimulsoft.Report的代码实现功能自学整理(一)
一、编译环境
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对象,这个是从工具栏跟拖动按钮似的拖上去的。
控件加载报表对象的方法
this.stiRibbonDesignerControl1.Report = this.MyReport;
MyReport要重新加载报表文件,注册数据集
MyReport = new StiReport();MyReport.Load("Reportstream.mrt");MyReport.RegData("tbB", fcgb);
七、预览界面
新建立了一个窗体,里面放了一个预览控件
预览控件预览报表的方法
this.MyReport.Render();this.stiRibbonViewerControl1.Report = this.MyReport;
同样的,MyReport要重新加载报表文件,注册数据集
八,运行效果
设计
预览
九、拿到没安装报表的电脑上正常运行需要的动态库
添加:
2019/3/12 打印时合并相同值的单元格
StiText dataText = new StiText();
dataText.ProcessingDuplicates = StiProcessingDuplicatesType.Merge;
靠在一起的能合并,不靠在一起的没法合并
Stimulsoft.Report的代码实现功能自学整理(一)相关推荐
- Stimulsoft.Report的代码实现功能自学整理(二)
一.如何往报表对象里传递外部变量值 有时候做报表需要把外部程序的变量值传递到报表中,比如当前登录的用户名.用户编号什么的.我是用了一个哈希表. Hashtable ht;ht = new Hashta ...
- 在报表开发工具Stimulsoft Report报表设计中使用存储过程?
本文主要介绍如何在Stimulsoft Report 设计中使用存储过程. 创建报表或仪表板时,通常使用存储过程来获取数据.在本文中,我们将介绍如何为常用数据源调用存储过程.使用存储过程创建数据源的复 ...
- 默认布局换行_自学整理 CSS Flex 布局
引言 最近记性特别不好,居然忘记 Flex 布局子项居中怎么写了,于是又看了一遍阮一峰老师的<Flex 布局教程>,为了能够加深记忆,边做记录边练习,因此整理本文作为自学笔记. 本文来源: ...
- eclipse linux 代码提示,Linux Eclipse代码提示功能设置(Java C/C++)
最近在Linux下开发,由于长期使用Visual Studio 2010,对代码提示功能情有独钟,现在在Linux下,使用Eclipse做开发,当然免不了怀念Visual Studio强悍的代码提示, ...
- 管理Discuz!代码分析的收集整理
管理Discuz!代码分析的收集整理 1.后台结构 @�L^SD+k#G0 后台首页提供了常用操作:用户(组)编辑,论坛基本备份等. k XS7]+mB8H0 2.PHPChina 开源社区门户&qu ...
- hexo博客yilia主题添加复制代码块功能
博客中的复制代码块功能还是挺实用的,本文参考自 这个博客,感谢并膜拜这位大佬,该博客应该是yilia主题添加复制代码块功能的首创,详细记录了整个过程,看起来比较繁琐(无贬义),所以我单独整理一份最终版 ...
- Stimulsoft.Report 2、 web报表的使用
Stimulsoft.Report web报表的使用,有需要的朋友可以参考下. 1.先用报表设计工具设计报表Report1.mrt(具体参照Stimulsoft_Reports 1. 报表制作http ...
- php SonarLint 代码规范检查提示整理
php SonarLint 代码规范检查提示整理 **1. add curly braces around the nested statement(在嵌套语句周围添加花括号)** 2.Refacto ...
- Intellij IDEA的代码提示功能如何设置
===========================记录Start=========================== Intellij IDEA是一款优秀的编程软件,相比较Eclipse之下它的 ...
最新文章
- 听得我都激动了……喝死奥巴马,你怎么看?
- 软件缘-网友个人精心打造的精品软件收集
- 五分钟带你入门TensorFlow
- nginx下部署vue项目
- logback 的 filter
- html5画板功能,JS实现canvas简单小画板功能
- HelloWorldProxy is a factory bean
- Spring 3.1配置文件和Tomcat配置
- The 2014 ACM-ICPC BeiJing D - Dire Wolf HDU - 5115 区间dp
- 计算机更改桌面,2010年职称计算机考试:更改桌面背景和颜色
- CSS3动画和VUE动画整理
- 简单的根据parentId生成树
- pandas将series所有值转变为字符串类型
- .NET Compact Framework 多线程下的等待事件
- 剑指Offer 64 求1+2+...+n
- mysql自助完成翻页代码_MySql实现翻页查询功能
- 大型门户网站的商业计划书(包括技术解决方案)
- ibm+i+to+mysql_IBM 的数据库Informix 常用代语法
- Day001-2021-07-29 变量定义/数据类型/基础运算 判断/循环/数组
- android imageview图片崩溃,安卓 ImageView 的使用及崩溃闪退、空白原因
热门文章
- Mac安装ffmpeg时 Failed to download resource quot;texi2htmlquot; 的解决办法
- 配置路由器交换机常见的坑
- 心得 ~ 使用 zlib库 解压缩 zip文件
- 微信群活码,一个能够将用户自动分流的工具
- python内置函数str的作用_Python3.6内置函数——str
- 相机标定中的相机焦距
- MIME sniffing攻击
- elasticsearch的查询器query与过滤器filter的区别
- ESP32 开发笔记(三)源码示例 8_DHT11_RMT 使用RMT实现读取DHT11温湿度传感器
- 今日头条面试——iOS开发岗