用QuickReport~~根据选择动态生成那些TQRDBText之类的等等东东~~~

解决方案 »

  1.   

    有很多种方法的。
    也有很多控件。
    有的用类似excel的方法。(不是调用excel)
    有的动态生成。且用户可以修改。
    我的email:
    [email protected]   
    我们可以研究一下的。
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls,QuickRpt, Qrctrls, Db, ADODB;type
      TForm1 = class(TForm)
        Button1: TButton;
        Query1: TADOQuery;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        QRep:TQuickRep;
        QRLabel:array of TQRLabel;
        QrdbText:array of TQrdbText;
        procedure MakeRep;
        procedure RepFree;
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2, Unit3;{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
       MakeRep;
       QRep.Preview;
       RepFree;
       //form2.QuickRep1.Preview;
    end;procedure TForm1.MakeRep;
    var Total,i:integer;
    begin
      QRep:=TQuickRep.Create(self);
      QRep.parent:=self;
      QRep.DataSet:=Query1;
      QRep.Bands.HasColumnHeader:=true; //指定其具有列头
      QRep.Bands.HasDetail:=true;      //指定其具有列值
     // QRep.AfterPreview:=FreeRept;      //FreeRept是一个过程,在
                                                //过程中自动释放掉报表 
      total:=Query1.Fields.Count;
      SetLength(QRLabel,total);
      SetLength(QrdbText,total);
      //动态生成列头
      For i:=0 to total - 1 do
        begin
          QRLabel[i]:=TQRLabel.Create(QRep.Bands.ColumnHeaderBand);
          QRLabel[i].parent:=QRep.Bands.ColumnHeaderBand;
          QRLabel[i].height:=QRep.Bands.ColumnHeaderBand.height-2;
          QRLabel[i].width:=Query1.Fields[i].DisplayWidth;
          QRLabel[i].frame.drawbottom:=true;    //指定Text是否有边框
          QRLabel[i].frame.drawleft:=true;
          QRLabel[i].frame.drawright:=true;
          QRLabel[i].frame.drawtop:=true;
          QRLabel[i].Top:=1;
          if i=0 then  QRLabel[i].Left:=0
          else QRLabel[i].left:=QRlabel[i-1].left+QRLabel[i-1].width;
          QRLabel[i].Caption:=Query1.Fields[i].DisplayLabel;
        end;
      //动态生成列值
      For i:=0 to total - 1 do
        begin
          QrdbText[i]:=TQrdbText.Create(QRep.Bands.DetailBand);
          QrdbText[i].parent:=QRep.Bands.DetailBand;
          QrdbText[i].Autosize:=false;
          QrdbText[i].height:=QRep.Bands.DetailBand.height;
          QrdbText[i].top:=-2;
          QrdbText[i].width:= QRLabel[i].width;
          if i=0 then QrdbText[i].Left:=0
          else QrdbText[i].left:=QrdbText[i-1].left+QrdbText[i-1].width;
          QrdbText[i].frame.drawbottom:=true;  //指定Text是否有边框
          QrdbText[i].frame.drawleft:=true;
          QrdbText[i].frame.drawright:=true;
          QrdbText[i].frame.drawtop:=true;
          QrdbText[i].Dataset:=Query1;
          QrdbText[i].DataField:=Query1.Fields[i].fieldname;
        end;   
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    MakeRep;
    QRep.Print;
    RepFree;
    end;procedure TForm1.RepFree;
    var i:integer;
    begin
      for i:=0 to ComponentCount-1 do
        begin
          if (Components[i].ClassType=TQRLabel) or (Components[i].ClassType=TQrdbText) then
          TQRLabel(Components[i]).Free;
        end;
    end;end.
      

  3.   

    TO:hansonboy(良) ~~呵呵~挺好玩的~~