报表XtraReport创建是实现

1.创建XtraReport报表程序

  一般设计这个程序是分着的,为了方便我就把他们合到一起

    首先创建一个Winform Application 在form1中放一个button,右键程序,添加新项 如下图,选择devExpressV16.2ReportWizard 点添加弹出的对话框中选择Empty Report

2. 在设计视图中随便添加几个Xlabel  加个ReportHeader ReportFooter  在加些内容  如图

3.点击设计器左上角蓝色角,保存到一个位置,方便以后我们调用

4. 好了 有了模板就可以调用了,在Form1上加个DocumentViewer 为button创建clik事件

 1  private void button1_Click(object sender, EventArgs e)
 2         {
 3             //第一种实现
 4             XtraReport1 report = new XtraReport1(); //实例化
 5             //加载模板
 6             report.LoadLayout(@"D:\C#练习\WindowsFormsApplication3\WindowsFormsApplication3\XtraReport1.repx");
 7             //false为纵向,true为横向
 8             report.Landscape = false;
 9             //绑定数据源
10             //report.DataSource = new DataTable();//我的报表中没有数据源,就不绑定了
11             //指定文档源
12             documentViewer1.DocumentSource = report;
13             report.CreateDocument();//创建文档
14             

当然可以不用模板,直接调用原版类实例化

1 //实例化这个report
2             XtraReport1 frx = new XtraReport1();
3             //纵向
4             frx.Landscape = false;
5             //文档视图源=我们创建的report
6             documentViewer1.DocumentSource = frx;
7             //显示文档
8             frx.CreateDocument();

两种效果是一样的

猜你喜欢

转载自www.cnblogs.com/xiaowie/p/8970531.html