一個qreport的例子:中文多行顯示,表格線在多行顯示時的擴充,擴充之後的手動分頁,文本式的反向報表(試過)

來源:互聯網
上載者:User

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, QuickRpt, QRCtrls, ExtCtrls, DB, ADODB, StdCtrls;

type
  TForm1 = class(TForm)
    ADOTable1: TADOTable;
    QuickRep1: TQuickRep;
    DetailBand1: TQRBand;
    meCutWord: TMemo;
    QRDBText2: TQRDBText;
    QRShape1: TQRShape;
    QRDBText1: TQRDBText;
    Label1: TLabel;
    QRShape2: TQRShape;
    QRLabel1: TQRLabel;
    procedure QRDBText1Print(sender: TObject; var Value: String);
    procedure FormCreate(Sender: TObject);
    procedure DetailBand1AfterPrint(Sender: TQRCustomBand;
      BandPrinted: Boolean);
    procedure QuickRep1BeforePrint(Sender: TCustomQuickRep;
      var PrintReport: Boolean);
    procedure DetailBand1BeforePrint(Sender: TQRCustomBand;
      var PrintBand: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
    hhh: array of Extended; // 用來記錄每條記錄擴充的高度
  end;
const
  MAXLEN= 21;

var
  Form1: TForm1;
  rows : integer;

implementation

{$R *.dfm}

(* DetailBand1AfterPrint, QuickRep1BeforePrint ,DetailBand1BeforePrint
都是用來當多行顯示的時候,qrdbtext將向下擴充,這時預設情況下,qrshape是不會向下擴充的,
上述三個處理就是用來解決這個問題的。
此外,還用到  rows : integer;
              hhh: array of Extended;
              setlength(hhh, 1000); //1000是代表的記錄的總數,這裡用1000是一個大概的表示。
                                    //可以的話應該精確表示,以避免空間的浪費
              quickRep1.Prepare;

*)

procedure TForm1.QRDBText1Print(sender: TObject; var Value: String);
var
  I: Integer;
  text:TQRDBText;
begin
  //解決中文多行顯示的問題。
  //dbtext.autosize:= false;
  //dbtext.autostretch := true;
  //dbtext.wrap := true;
  text := sender as TQRDBText;
  meCutWord.Font.Assign(text.Font);   //   指定字型
    meCutWord.Width := text.Width;//   指定寬度
    meCutWord.Lines.Clear;//   清除上一次的東西
    meCutWord.Lines.Text := Value;   //   把 value assign 進去
    Value := meCutWord.Lines.Strings[0];
    for I := 1 to meCutWord.Lines.Count - 1 do
    begin
      Value := Value + #13 + meCutWord.Lines.Strings[i];//   逐行取出再塞回去
    end;

 

end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  setlength(hhh, 1000);
  QuickRep1.Prepare;
  quickRep1.PreviewModal;
end;

procedure TForm1.DetailBand1AfterPrint(Sender: TQRCustomBand;
  BandPrinted: Boolean);
begin
  hhh[rows] := QuickRep1.bands.DetailBand.Expanded;
  rows := rows + 1;
end;

procedure TForm1.QuickRep1BeforePrint(Sender: TCustomQuickRep;
  var PrintReport: Boolean);
var
  i:integer;
begin
  rows := 1;
  for I := 0 to quickrep1.Bands.DetailBand.ControlCount - 1 do    // Iterate
  begin
    if QuickRep1.Bands.DetailBand.Controls[i] is TQRShape then
      (QuickRep1.Bands.DetailBand.Controls[i] as TQRShape).Height :=
        QuickRep1.Bands.DetailBand.Height;
  end;    // for
end;

procedure TForm1.DetailBand1BeforePrint(Sender: TQRCustomBand;
  var PrintBand: Boolean);
var
  i:Integer;
begin

  for I := 0 to quickrep1.Bands.DetailBand.ControlCount - 1 do    // Iterate
  begin
    if QuickRep1.Bands.DetailBand.Controls[i] is TQRShape then
    begin
      (QuickRep1.Bands.DetailBand.Controls[i] as TQRShape).top := 1;
      (QuickRep1.Bands.DetailBand.Controls[i] as TQRShape).Size.Height :=
        QuickRep1.Bands.DetailBand.Size.Height + hhh[rows];
    end;
  end;
end;

end. 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.