当前位置:网站首页>c# 水晶报表打印
c# 水晶报表打印
2022-07-02 10:23:00 【coder i++】
转:https://www.cnblogs.com/aitong/p/10717786.html
水晶报表介绍
水晶报表是 vs 早期版本自带的一款报表控件。vs2017不自带水晶报表,需要自行安装。虽然水晶报表是收费控件,但是微软已经付过钱了,所以vs自带的水晶报表可以直接使用。
如果项目是 .net 4.0 以上版本,需要修改 App.config 文件。因为水晶报表的 .net 版本可能低于 .net 4.0
在软件发布的时候需要把对应的config文件一起发布,否则也无法使用水晶报表
<startup useLegacyV2RuntimeActivationPolicy="true"> //在这一行加入 useLegacyV2RuntimeActivationPolicy="true"
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
在解决方案资源管理器中添加数据集DataSet1.xsd,在数据集中添加 DataTable.
新建 Crystal Reports 文件
在解决方案资源管理器中新建 Crystal Reports 文件: CrystalReport1.rpt 。添加后左侧会出现 “字段资源管理器” 。如果不小心关掉字段资源管理器,可以在 “视图” “其它窗口” “文档大纲” 将其调出。
vs的工具箱中也会出现相应的控件。可以将文本对象添加到报表中。 文本对象常用属性:CanGrow (可以自动换行) HorAlignment (居中,靠左,靠右)。
在数据库字段右键选择数据库专家。添加项目数据中的 DataTable1
在 “组名字段” 右键插入组。选择 DataTable1 中的字段 ,排序方式选择按原始顺序(水晶报表的排序方式不实用,一般在设置 DataTable 时自行排序)。
数据库字段中的 Name Sex 可以拖到报表的详细资料中。报表的页眉会自动添加文本框。文本框的内容可修改为姓名,性别。
在界面中添加显示控件:CrystalReportViewer 重命名为crv
在窗口中创建报表对象并添加数据,显示到 CrystalReportViewer 上面。可以直接打印,也可以通过控件上的打印按钮打印。
using CrystalDecisions.CrystalReports.Engine;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CrTest
{
public partial class Form1 : Form
{
public Form1(bool directPrint = false)
{
InitializeComponent();
DataSet1 ds = new DataSet1();
ds.DataTable1.Rows.Add("组1", "张1", "男");
ds.DataTable1.Rows.Add("组3", "王1", "男");
ds.DataTable1.Rows.Add("组2", "李1", "男");
ds.DataTable1.Rows.Add("组1", "张2", "男");
ds.DataTable1.Rows.Add("组1", "张3", "女");
ds.DataTable1.Rows.Add("组1", "张4", "男");
ds.DataTable1.Rows.Add("组2", "李2", "男");
ds.DataTable1.Rows.Add("组2", "李3", "女");
ds.DataTable1.Rows.Add("组2", "李4", "男");
ds.DataTable1.Rows.Add("组3", "王2", "男");
ReportClass cr = new CrystalReport1();
cr.SetDataSource(ds);
TextObject title = (TextObject)cr.ReportDefinition.ReportObjects["Text1"];
title.Text = "人员表格";
if (directPrint)
{
PrintDialog print = new PrintDialog();
if (print.ShowDialog() == DialogResult.OK)
{
cr.PrintOptions.PrinterName = print.PrinterSettings.PrinterName;
cr.PrintToPrinter(1, false, 0, 0);
}
}
this.crv.ReportSource = cr;
}
}
}
边栏推荐
- How to use SAP's metadata framework (MDF) to build custom business rules?
- P3807 [template] Lucas theorem /lucas theorem
- Halcon extract orange (Orange)
- Essential for operation and maintenance - Elk log analysis system
- Integral link, inertia link and proportion link in Simulink
- Partner cloud form strong upgrade! Pro version, more extraordinary!
- [Blue Bridge Cup] children's worship circle
- Gee learning notes 2
- selenium的特点
- 693. Travel sequencing (map + topology)
猜你喜欢
Skillfully use SSH to get through the Internet restrictions
The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner
[indomitable medal activity] life goes on and writing goes on
不会看器件手册的工程师不是个好厨子
Will your sleep service dream of the extra bookinfo on the service network
Partner cloud form strong upgrade! Pro version, more extraordinary!
[OpenGL] notes 29. Advanced lighting (specular highlights)
Unity small map production [2]
Selenium, element operation and browser operation methods
Development skills of rxjs observable custom operator
随机推荐
ensp简单入门
你的 Sleep 服务会梦到服务网格外的 bookinfo 吗
Can automatically update the universal weekly report template, you can use it with your hand!
瀏覽器驅動的下載
693. 行程排序(map + 拓扑)
Redis database persistence
Partner cloud form strong upgrade! Pro version, more extraordinary!
On flow delivery between microservices
selenium 在pycharm中安装selenium
Gee learning notes 2
ArrayList and LinkedList
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
Explanation: here is your UFO, Goldbach conjecture
题解:《压缩技术》(原版、续集版)
Mysql5.7 installation super easy tutorial
刚好1000粉丝,记录一下
浏览器驱动的下载
Principle analysis of security rememberme
2022 zero code / low code development white paper [produced by partner cloud] with download
Stone merging Board [interval DP] (ordinary stone Merging & Ring Stone merging)