原創|其它|編輯:郝浩|2012-08-27 21:19:41.000|閱讀 2796 次
概述:在DevExpress XtraReport中,每一個報表都是XtraReport或者其子類。打個比方說,XtraReport就好象Windows Forms。同樣的道理,所有的form都Form類的子類。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
在DevExpress 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);
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:轉載