云自无心水自闲

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

DevExpress的XtraReports使用心得(帮助文档)

Posted on 2006-09-22 10:20 云自无心水自闲 阅读(14434) 评论(1)  编辑  收藏 所属分类: .Net
在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的类结构层次图:




评论

# re: DevExpress的XtraReports使用心得(帮助文档)  回复  更多评论   

2010-02-03 13:03 by kikosi
很不错,找了好久

只有注册用户登录后才能发表评论。


网站导航: