使用fastreport以代码方式创建报表

Report report = new Report();
// register the "Products" table
report.RegisterData(dataSet1.Tables["Products"], "Products");
// enable it to use in a report
report.GetDataSource("Products").Enabled = true;
// create A4 page with all margins set to 1cm
ReportPage page1 = new ReportPage();
page1.Name = "Page1";
report.Pages.Add(page1);
// create ReportTitle band
page1.ReportTitle = new ReportTitleBand();
page1.ReportTitle.Name = "ReportTitle1";
// set its height to 1.5cm
page1.ReportTitle.Height = Units.Centimeters * 1.5f;
// create group header
GroupHeaderBand group1 = new GroupHeaderBand();
group1.Name = "GroupHeader1";
group1.Height = Units.Centimeters * 1;
// set group condition
group1.Condition = "[Products.ProductName].Substring(0, 1)";
// add group to the page.Bands collection
page1.Bands.Add(group1);
// create group footer
group1.GroupFooter = new GroupFooterBand();
group1.GroupFooter.Name = "GroupFooter1";
group1.GroupFooter.Height = Units.Centimeters * 1;
// create DataBand
DataBand data1 = new DataBand();
data1.Name = "Data1";
data1.Height = Units.Centimeters * 0.5f;
// set data source
data1.DataSource = report.GetDataSource("Products");
// connect databand to a group
group1.Data = data1;
// create "Text" objects
// report title
TextObject text1 = new TextObject();
text1.Name = "Text1";
// set bounds
text1.Bounds = new RectangleF(0, 0,
Units.Centimeters * 19, Units.Centimeters * 1);
// set text
text1.Text = "PRODUCTS";
// set appearance
text1.HorzAlign = HorzAlign.Center;
text1.Font = new Font("Tahoma", 14, FontStyle.Bold);
// add it to ReportTitle
page1.ReportTitle.Objects.Add(text1);
// group
TextObject text2 = new TextObject();
text2.Name = "Text2";
text2.Bounds = new RectangleF(0, 0,
Units.Centimeters * 2, Units.Centimeters * 1);
text2.Text = "[[Products.ProductName].Substring(0, 1)]";
text2.Font = new Font("Tahoma", 10, FontStyle.Bold);
Working with Windows.Forms 23
// add it to GroupHeader
group1.Objects.Add(text2);
// data band
TextObject text3 = new TextObject();
text3.Name = "Text3";
text3.Bounds = new RectangleF(0, 0,
Units.Centimeters * 10, Units.Centimeters * 0.5f);
text3.Text = "[Products.ProductName]";
text3.Font = new Font("Tahoma", 8);
// add it to DataBand
data1.Objects.Add(text3);
// group footer
TextObject text4 = new TextObject();
text4.Name = "Text4";
text4.Bounds = new RectangleF(0, 0,
Units.Centimeters * 10, Units.Centimeters * 0.5f);
text4.Text = "Count: [CountOfProducts]";
text4.Font = new Font("Tahoma", 8, FontStyle.Bold);
// add it to GroupFooter
group1.GroupFooter.Objects.Add(text4);
// add a total
Total groupTotal = new Total();
groupTotal.Name = "CountOfProducts";
groupTotal.TotalType = TotalType.Count;
groupTotal.Evaluator = data1;
groupTotal.PrintOn = group1.Footer;
// add it to report totals
report.Dictionary.Totals.Add(groupTotal);
// run the report
report.Show();

生成的报表如下:

fastreport常见问题:https://www.fastreportcn.com/FAQ/index.html

本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:FastReport控件中文网 [http://www.fastreportcn.com/]

原文地址:https://www.cnblogs.com/zhaogaojian/p/8349664.html

时间: 2025-01-12 04:14:14

使用fastreport以代码方式创建报表的相关文章

c# 纯代码方式创建快捷方式

using System; using System.Collections.Generic; using System.Text; using Microsoft.Win32; using System.Runtime.InteropServices; namespace ShortcutNamespace { class MyShortcut { [StructLayout(LayoutKind.Sequential)] public struct FILETIME { uint dwLow

【案例分享】使用ActiveReports报表工具,在.NET MVC模式下动态创建报表

提起报表,大家会觉得即熟悉又陌生,好像常常在工作中使用,又似乎无法准确描述报表.今天我们来一起了解一下什么是报表,报表的结构.构成元素,以及为什么需要报表. 什么是报表 简单的说:报表就是通过表格.图表等形式来动态显示数据,并为使用者提供浏览.打印.导出和分析的功能,可以用公式表示为: 报表 = 多样的布局 + 动态的数据 + 丰富的输出 报表通常包含以下组成部分: 报表首页:在报表的开始处,用来显示报表的标题.图形或说明性文字,每份报表只有一个报表首页. 页眉:用来显示报表中的字段名或对记录的

DevExpress XtraReports 入门六 控件以程序方式创建一个 交叉表 报表

原文:DevExpress XtraReports 入门六 控件以程序方式创建一个 交叉表 报表 本文只是为了帮助初次接触或是需要DevExpress XtraReports报表的人群使用的,为了帮助更多的人不会像我这样浪费时间才写的这篇文章,高手不想的看请路过 本文内容来DevExpress XtraReports帮助文档,如看过类似的请略过. 废话少说 开始正事 在继续本示例之前,要把所有 必需的程序集 添加到项目的 引用 列表中,并且把一个按钮拖放到窗体上. 然后,以下列方式接管此按钮的

用xib和代码的方式创建带边框和圆角的按钮

一.通过xib快速设置圆角 利用User Defined Runtime Attributes 进行设置 身份检查器 详细步骤介绍 点击UI控件 点击 Xcode 右侧上方身份检查器(左起第三个按钮) 找到 Runtime Attributes 属性,通过Key Path 和 Value 进行设置 设置圆角需要到的Key Path: layer.cornerRadius ,注意该 key 对应 Value 的 type 应该设置为 String(设置圆角) keyPath值layer.masks

iOS_16_控制器切换_modal_代码方式

最终效果图: main.storyboard BeyondViewController.h // // BeyondViewController.h // 16_控制器切换方式1_Modal_通过代码方式 // // Created by beyond on 14-7-30. // Copyright (c) 2014年 com.beyond. All rights reserved. // #import <UIKit/UIKit.h> @interface BeyondViewContro

SSH(Struts2+Spring+Hibernate)框架搭建流程&lt;注解的方式创建Bean&gt;

此篇讲的是MyEclipse9工具提供的支持搭建自加包有代码也是相同:用户登录与注册的例子,表字段只有name,password. SSH,xml方式搭建文章链接地址:http://www.cnblogs.com/wkrbky/p/5912810.html 一.Hibernate(数据层)的搭建: 实现流程 二.Spring(注入实例)的使用: 实现流程 三.Struts2(MVC)的搭建: 实现流程 这里注意一点问题: Struts2与Hibernate在一起搭建,antlr包,有冲突.MyE

(3)通过声明的方式创建ApplicationContext对象

时间是一切财富中最宝贵的财富. -- 德奥弗拉斯多 在%spring%/docs/spring-framework-reference/htmlsingle/index.html文件的 5.14.4 Convenient ApplicationContext instantiation for web applications. 如果要创建ApplicationContext的实例,有两种方法:一种是使用代码的方式,另一种是使用声明的方式. 使用代码的方式创建ApplicationContext

使用jqplot创建报表(一) 初学后写的第一个案例源码

一.初学后写的第一个案例源码 效果图: 代码如下: <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ include file="common.jsp"%> <html> <head> <script type="text/javascript" src=&q

VB 在Visio 2010 以编程方式创建子进程图

在2010年Visio以编程方式创建子进程图 Office 2010  https://msdn.microsoft.com/en-us/library/gg650651.aspx 简介: 学习如何创建子流程图表以编程方式在Microsoft Visio 2010. 最后修改: 2011年4月07日 适用于: Office 2010 | SharePoint Server 2010 | 2010 | Visio Visio溢价2010 在这篇文章中 概述创建一个流程图创建子流程页面移动一个形状子