Quick Report 的Group header和Group footer的跨頁解決方法 |
|
energybody
一般會員 發表:44 回覆:32 積分:15 註冊:2007-04-12 發送簡訊給我 |
小弟用 Quick Report 時, 為了解決 Group header band 和 Detail band 和 Group footer band 的跨頁問題曾經求助 delphi ktop, 但是用 linked band 不能解決問題, 所以上網去尋找, 終於找到 Quick Report 的跨頁問題的解決方法, 小弟將它改寫成小弟程式需要的方式, 提供給各位參考.
報表建立時的參數設定: rptDO:=TRptDO.Create(Application); try with rptDO do begin ... CalculateAcrossPage:=True; <-- 要計算跨頁 StoreAcrossPage:=True; <--儲存跨頁資料 Prepare; QRPrinter.Free; QRPrinter:=nil; CalculateAcrossPage:=True; StoreAcrossPage:=False; <--將跨頁的資料比對 prepare; pTTLPAGE:=rptDO.PageNumber;<--重新計算頁數 QRPrinter.Free; QRPrinter:=nil; PreviewModal; ... end; 報表的程式 type TrptDO = class(TQuickRep) ... private ... GroupCounter: Integer; GroupTotalHeight: array [0..199] of Double;<--預設200筆資料 public ... CalculateAcrossPage, StoreAcrossPage: Boolean; end; procedure TrptDO.QuickRepBeforePrint(Sender: TCustomQuickRep; var PrintReport: Boolean); begin if CalculateAcrossPage then GroupCounter:=IfThen(StoreAcrossPage,-1,0); <--預設計数 ... end; procedure TrptDO.QRGroup1BeforePrint(Sender: TQRCustomBand; var PrintBand: Boolean); begin if CalculateAcrossPage then <--計算是否要跨頁,預留 5% 的空間,因為 Quick Report 會計算不準確 begin if (not StoreAcrossPage) and (AvailableSpace < (GroupTotalHeight[GroupCounter] (GroupTotalHeight[GroupCounter]/20))) then rptDO.NewColumn; inc(GroupCounter); end; ... end; procedure TrptDO.QRGroup1AfterPrint(Sender: TQRCustomBand; var PrintBand: Boolean); begin ... if CalculateAcrossPage and StoreAcrossPage then GroupTotalHeight[GroupCounter]:=Sender.Size.Length Sender.Expanded; <儲存 Group Height end; procedure TrptDO.QRBand1AfterPrint(Sender: TQRCustomBand; var PrintBand: Boolean); begin ... if CalculateAcrossPage and StoreAcrossPage then GroupTotalHeight[GroupCounter]:=GroupTotalHeight[GroupCounter] Sender.Size.Length Sender.Expanded; <--(加入 Detail Band height) end; ... 中間有多少個 band,在 AfterPrint 中要加入 band height procedure TrptDO.QRBand3AfterPrint(Sender: TQRCustomBand; var PrintBand: Boolean); begin ... if CalculateAcrossPage and StoreAcrossPage then GroupTotalHeight[GroupCounter]:=GroupTotalHeight[GroupCounter] Sender.Size.Length Sender.Expanded; <--加入 footer height end; 如此就完成一個 Group 的總長度, 在 Group BeforePrint 時比對一頁剩下的長度( 5%), 如果小於就跳頁. 此程式很簡單卻很有用,希望對大家有所幫助. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |