云自无心水自闲

天平山上白云泉,云自无心水自闲。何必奔冲山下去,更添波浪向人间!
posts - 134, comments - 238, trackbacks - 0, articles - 6
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

2006年9月22日

一个普通的XtraReport报表一般包含数个包含报表控件的带. 在这里介绍一个XtraReports中的几种不同类型的带, 他们都有一些什么用途, 又是如何添加,编辑,删除.

Report Bands

在把报表添加到应用之后, 缺省的样子如下图所示. 可以看到, 报表被初始化分为3个基本的带(页头, 明细, 和页脚), 这些带中可以添加不同的报表控件.

每一种带指明了控件在报表中是怎样定位和被打印的, 即确定了打印的顺序和次数. 注意, 有些<band strips>包含了带是如何被打印的信息, 比如: PageHeader和PageFooter就说明了是每一页都有这一带的.

在创建报表时, 可以添加或者删除任意的带. 在XtraReports中有很多不同类型的带, 每一个都是<Band>的子类. 列举如下:

Bands类 描述
TopMarginBand 用于放置出现在报表每页页头最上面的控件
ReportHeaderBand 用于放置出现在报表开头的控件
PageHeaderBand 用于放置出现在报表页上面, 仅次于TopMarginBand位置的控件. 主要是用于放置需要分页的表格的头,
GroupHeaderBand 用于放置明细带中分组记录的头部控件. 
DetailBand 用于显示绑定数据的每条记录
DetailReportBand 用于创建主从报表. 主从关系由从报表的XtraReportsBase.DataMember属性指定
GroupFooterBand 用于放置明细带中分组记录下方的控件
PageFooterBand 用于放置报表页下方的控件
ReportFooterBand 用于放置报表结束的控件
BottomMarginBand 用于放置报表每页最下方的控件

下图显示了不同类型的带的相对位置:

TopMarginBand and BottomMarginBand

ReportHeaderBand and ReportFooterBand

PageHeaderBand and PageFooterBand

GroupHeaderBand and GroupFooterBand

DetailBand

报表的预览显示的不是带本身, 而是<PrintingSystem>的输出. PageHeaderBand, PageFooterBand, TopMarginBand和BottomMarginBand在报表预览的每一页都有输出. ReportHeaderBand和ReportFooterBand类只显示一次. GroupHeaderBand和GroupFooterBand出现在每个记录组中.



posted @ 2006-09-22 11:05 云自无心水自闲 阅读(1019) | 评论 (0)编辑 收藏

在XtraReport中, 每一个报表都是XtraReport或者其子类. 打个比方说, XtraReport就好象Windows Forms. 同样的道理, 所有的form都Form类的子类.

  XtraReport中的报表类可以与数据绑定也可以不绑定. 如果要创建一个绑定数据的报表, 需要查看<数据绑定>和<绑定数据控件>这两个主题的帮助.
  在创建一个报表时, 可以从已有的报表中加载样式和布局, 样式中包含了报表控件外观的属性值, 而布局包含了报表的结构信息. 另外, 还可以从其他报表系统中导入报表, 比如: Access, 水晶报表等等, 如果要详细了解XtraReport的导入功能, 请参阅<Importing Overview>主题.
  报表类(XtraReport的子类)创建后, 就可以生成其实例. 需要注意的是, XtraReport对象可以在Windows Forms中使用也可以在Asp.net中使用. 在Windows应用中使用报表, 通常需要维护报表的<Printing System>, 这个对象提供了报表的输出功能.

  创建报表有两种方式, 一种是简单地添加一个"模板"报表, 一种是通过报表向导来创建报表. 在报表添加到项目后, 报表设计器提供了大量的设计时元素来加快简化报表的创建. XtraReport工具箱包含了所有的控件, Report Navigator可以浏览整个报表, Feild List可以拖放数据字段来创建与数据绑定的报表控件.
   XtraReport的所有报表都是由<Report Band>和<Report Control>组成的.
public class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
   
private DevExpress.XtraReports.UI.DetailBand Detail;
   
private DevExpress.XtraReports.UI.PageHeaderBand PageHeader;
   
private DevExpress.XtraReports.UI.PageFooterBand PageFooter;
   
private DevExpress.XtraReports.UI.XRLabel xrLabel1;
   
private DevExpress.XtraReports.UI.XRLabel xrLabel2;

   
private System.ComponentModel.Container components = null;

   
public XtraReport1()
   {
      InitializeComponent();
   }

   
protected override void Dispose( bool disposing )
   {
      
if( disposing )
      {
         
if(components != null)
         {
            components.Dispose();
         }
      }
      
base.Dispose( disposing );
   }
  
   
// .
 
  然后开始创建报表的结构, 首先在XtraReportBase.Bands属性中添加Bands, 然后在相应的Bands的XRControl.Controls属性中添加控件. 报表带和控件的添加方法一般是这样的
// Add Detail, PageHeader and PageFooter bands to the report's collection of bands.
this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] {this.Detail, this.PageHeader, this.PageFooter});

// Add two XRLabel controls to the Detail band.
this.Detail.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] {this.xrLabel1, this.xrLabel2});

最后创建好的报表可以输出给用户看了
// Create a report.
XtraReport1 report = new XtraReport1();

// Create the report's document so it can then be previewed, printed or exported.
// NOTE: Usually you don't need to call this method as it's automatically called by all of the following methods.
// See the corresponding member topic to find out when it needs to be called.
report.CreateDocument();

// Show the form with the report's print preview.
report.ShowPreview();

// Print the report in a dialog and "silent" mode.
report.PrintDialog();
report.Print();

// Open the report in the End-User designer
report.RunDesigner();

// Export the report.
report.CreateHtmlDocument("report.html");
report.CreatePdfDocument(
"report.pdf");
report.CreateImage(
"report.jpg", System.Drawing.Imaging.ImageFormat.Gif);

附: XtraReport的类结构层次图:

posted @ 2006-09-22 10:20 云自无心水自闲 阅读(1980) | 评论 (0)编辑 收藏