一个qreport的例子:中文多行显示,表格线在多行显示时的扩展,扩展之后的手动分页,文本式的反向报表(试过)

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. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值