如何用fastreport打印stringgrid中的数据?

解决方案 »

  1.   

    dbgrid  的给你一种方法。报表是预先做好的。fastreport中,放一个master data,cross date,master header  两个交叉处放[Header] 和[cell] procedure TqueryForm.BitBtn2Click(Sender: TObject);
    begin
      frUserDataset1.RangeEndCount := dbgrid1.FieldCount;
      frUserDataset2.RangeEndCount := dbgrid1.FieldCount;
      frReport1.ShowReport;
    end;procedure TqueryForm.frReport1GetValue(const ParName: String;
      var ParValue: Variant);
    begin
     if ParName = 'Cell' then
        ParValue := dbgrid1.Fields[frUserDataset1.RecNo].Value;
      if ParName = 'Header' then
        ParValue := dbgrid1.Fields[frUserDataset2.RecNo].FieldName; 
    end;
      

  2.   

    我的程序里用的是stringgrid啊,并不是dbgrid,所以不知道怎么用fastreport来打印!
      

  3.   

    以下有一個stringgrid 示例。procedure TForm1.Button1Click(Sender: TObject);
    begin
      ColDataset.RangeEnd := reCount;
      ColDataset.RangeEndCount := StringGrid1.ColCount;
      RowDataset.RangeEnd := reCount;
      RowDataset.RangeEndCount := StringGrid1.RowCount;
      frReport1.ShowReport;
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      i, j: Integer;
    begin
      for i := 0 to StringGrid1.ColCount - 1 do
        for j := 0 to StringGrid1.RowCount - 1 do
          StringGrid1.Cells[i, j] := IntToStr(j * StringGrid1.ColCount + i + 1);
    end;procedure TForm1.frReport1GetValue(const ParName: string;
      var ParValue: Variant);
    begin
      if AnsiCompareText(ParName, 'Cell') = 0 then
        ParValue := StringGrid1.Cells[ColDataset.RecNo, RowDataset.RecNo];
    end;procedure TForm1.frReport2GetValue(const ParName: string;
      var ParValue: Variant);
    begin
      if AnsiCompareText(ParName, 'Cell1') = 0 then
        ParValue := StringGrid1.Cells[0, RowDataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell2') = 0 then
        ParValue := StringGrid1.Cells[1, RowDataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell3') = 0 then
        ParValue := StringGrid1.Cells[2, RowDataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell4') = 0 then
        ParValue := StringGrid1.Cells[3, RowDataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell5') = 0 then
        ParValue := StringGrid1.Cells[4, RowDataset.RecNo]
    end;procedure TForm1.frReport3GetValue(const ParName: string;
      var ParValue: Variant);
    begin
      if AnsiCompareText(ParName, 'Cell1') = 0 then
        ParValue := StringGrid1.Cells[0, Dataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell2') = 0 then
        ParValue := StringGrid1.Cells[1, Dataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell3') = 0 then
        ParValue := StringGrid1.Cells[2, Dataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell4') = 0 then
        ParValue := StringGrid1.Cells[3, Dataset.RecNo]
      else if AnsiCompareText(ParName, 'Cell5') = 0 then
        ParValue := StringGrid1.Cells[4, Dataset.RecNo]
    end;procedure TForm1.DatasetCheckEOF(Sender: TObject; var Eof: Boolean);
    begin
      Eof := Dataset.RecNo >= StringGrid1.RowCount;
    end;
      

  4.   

    我用过一个控件,很不错,叫sailPrint,专门打印stringgrid,你找找.找不到的话联系我,我发给你