我利用sql 查询出 多条数据 ,显示在dbgrid框中!(条目不定)  现在我想用 quickreport 打印出dbgrid中的数据  请问如何打印?!--就用quickreport中的控件

解决方案 »

  1.   

    报表的数据源连接查询的dataset,然后用循环把字段名读进来就可以了,标签和QRDBText都用数组。
      

  2.   

    谢谢楼上可是我的 条目不定 怎么知道 划多少个qrdbtext?
      

  3.   

    根据QUERY的字段数目动态创建QTDBTEXT,我写过类似的。
    最好在ONNEEDDATA手动写入
      

  4.   

    我这儿是打印的StringGrid里的数据,字段的多少是不定的。代码如下:procedure TForm1.SpeedButton11Click(Sender: TObject);
    Var
      Index_R ,ALeft: Integer;
      Index : Integer;
    begin
      QRFree;
      StringGrid_File('D:\AAA.TXT');
      if Not LinkTextFile then
      begin
        ShowMessage('失败');
        Exit;
      end;
      //
      QuickRep1.DataSet := ADOTable1;
      Index_R := ReSize(StringGrid1.Width);
      ALeft := 13;
      Create_Title(TitleBand1,ALeft,24,Size_(0),20,
         HeaderControl1.Sections[0].Text,taLeftJustify);
      with Create_QRDBText(DetailBand1,ALeft,8,Size_(0),20,
             StringGrid1.Font,taLeftJustify) do
      begin
        DataSet := ADOTable1;
        DataField := ADOTable1.Fields[0].DisplayName;
      end;
      ALeft := ALeft + Size_(0) + 1;
      For Index := 1 to ADOTable1.FieldCount - 1 do
      begin
        Create_VLine(TitleBand1,ALeft - 13,16,1,40);
        Create_Title(TitleBand1,ALeft,24,Size_(Index),20,
          HeaderControl1.Sections[Index].Text,taLeftJustify);
        Create_VLine(DetailBand1,ALeft - 13,-1,1,31);
        with Create_QRDBText(DetailBand1,ALeft ,8,Size_(Index),20,
             StringGrid1.Font,taLeftJustify) do
        begin
          DataSet := ADOTable1;
          DataField := ADOTable1.Fields[Index].DisplayName;
        end;
        ALeft := ALeft + Size_(Index) + 1;
      end;
      QuickRep1.Preview;
    end;