DevExpress的XtraReports使用心得(幫助文檔)
Posted on 2006-09-22 10:20 云自無心水自閑 閱讀(14543) 評論(1) 編輯 收藏 所屬分類: .Net在XtraReport中, 每一個報表都是XtraReport或者其子類. 打個比方說, XtraReport就好象Windows Forms. 同樣的道理, 所有的form都Form類的子類.

? XtraReport中的報表類可以與數(shù)據(jù)綁定也可以不綁定. 如果要創(chuàng)建一個綁定數(shù)據(jù)的報表, 需要查看<數(shù)據(jù)綁定>和<綁定數(shù)據(jù)控件>這兩個主題的幫助.
? 在創(chuàng)建一個報表時, 可以從已有的報表中加載樣式和布局, 樣式中包含了報表控件外觀的屬性值, 而布局包含了報表的結(jié)構(gòu)信息. 另外, 還可以從其他報表系統(tǒng)中導入報表, 比如: Access, 水晶報表等等, 如果要詳細了解XtraReport的導入功能, 請參閱<Importing Overview>主題.
? 報表類(XtraReport的子類)創(chuàng)建后, 就可以生成其實例. 需要注意的是, XtraReport對象可以在Windows Forms中使用也可以在Asp.net中使用. 在Windows應用中使用報表, 通常需要維護報表的<Printing System>, 這個對象提供了報表的輸出功能.
? 創(chuàng)建報表有兩種方式, 一種是簡單地添加一個"模板"報表, 一種是通過報表向?qū)韯?chuàng)建報表. 在報表添加到項目后, 報表設(shè)計器提供了大量的設(shè)計時元素來加快簡化報表的創(chuàng)建. XtraReport工具箱包含了所有的控件, Report Navigator可以瀏覽整個報表, Feild List可以拖放數(shù)據(jù)字段來創(chuàng)建與數(shù)據(jù)綁定的報表控件.
?? XtraReport的所有報表都是由<Report Band>和<Report Control>組成的.
? 然后開始創(chuàng)建報表的結(jié)構(gòu), 首先在XtraReportBase.Bands屬性中添加Bands, 然后在相應的Bands的XRControl.Controls屬性中添加控件. 報表帶和控件的添加方法一般是這樣的
最后創(chuàng)建好的報表可以輸出給用戶看了
附: XtraReport的類結(jié)構(gòu)層次圖:


? XtraReport中的報表類可以與數(shù)據(jù)綁定也可以不綁定. 如果要創(chuàng)建一個綁定數(shù)據(jù)的報表, 需要查看<數(shù)據(jù)綁定>和<綁定數(shù)據(jù)控件>這兩個主題的幫助.
? 在創(chuàng)建一個報表時, 可以從已有的報表中加載樣式和布局, 樣式中包含了報表控件外觀的屬性值, 而布局包含了報表的結(jié)構(gòu)信息. 另外, 還可以從其他報表系統(tǒng)中導入報表, 比如: Access, 水晶報表等等, 如果要詳細了解XtraReport的導入功能, 請參閱<Importing Overview>主題.
? 報表類(XtraReport的子類)創(chuàng)建后, 就可以生成其實例. 需要注意的是, XtraReport對象可以在Windows Forms中使用也可以在Asp.net中使用. 在Windows應用中使用報表, 通常需要維護報表的<Printing System>, 這個對象提供了報表的輸出功能.
? 創(chuàng)建報表有兩種方式, 一種是簡單地添加一個"模板"報表, 一種是通過報表向?qū)韯?chuàng)建報表. 在報表添加到項目后, 報表設(shè)計器提供了大量的設(shè)計時元素來加快簡化報表的創(chuàng)建. XtraReport工具箱包含了所有的控件, Report Navigator可以瀏覽整個報表, Feild List可以拖放數(shù)據(jù)字段來創(chuàng)建與數(shù)據(jù)綁定的報表控件.
?? 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?);
???}
??
???//?
.
? {
???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?);
???}
??
???//?

? 然后開始創(chuàng)建報表的結(jié)構(gòu), 首先在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});
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});
最后創(chuàng)建好的報表可以輸出給用戶看了
//?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);
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的類結(jié)構(gòu)層次圖:
