楼主的意思是多页套打主从表单据,要使用fr的group band,而且在数据集中有分组的字段,表示每行记录的所在分组号(varchar(50)) 、下面是我写的公共的分页套打代码: //套打数据集 Procedure PrintPre_Com(vw_mst, vw_Det, FKFld, KFldVal, FDKeyFld, DetFlds, NumFld, MstFlds, DetTable:String; MPrintQry, DPrintQry :TAdoQuery); var i, j, i1, i2:integer; Qrytmp :TAdoQuery; PrintLines :Integer; Sqls ,Fld :String; PrintCompName :string; begin PrintLines :=GetPrintLines;//读取结算单打印格式中的行数 PrintCompName :=GetPrintCompName; //打印格式中的公司标题 with MPrintQry do begin close; sql.Text:='Select * from '+vw_mst +' where '+FKFld +'='''+KFldVal+''''; open;end; Qrytmp :=createBatchQry; with Qrytmp do begin close; sql.Text:='Select * from '+vw_Det+' where '+FKFld +'='''+KFldVal+''' Order By '+FDKeyFld; open;end;
//拼接临时的数据集的Sql。 Sqls :=' Select Re as CurrPage, Re as PageCount, Re as PrintCompName ' ; For i :=1 to GetMaskCount(DetFlds, '\') do begin Sqls :=Sqls +',Re as ' +GetMaskString(DetFlds, '\', i); end; For i :=1 to GetMaskCount(NumFld, '\') do begin Sqls :=Sqls +',' +GetMaskString(NumFld, '\', i); end; For i :=1 to GetMaskCount(MstFlds, '\') do begin Sqls :=Sqls +', Re as ' +GetMaskString(MstFlds, '\', i); end;
Sqls :=Sqls +' from ' +DetTable +' where 1=2 '; with DPrintQry do begin close; sql.Text :=Sqls; open; end; i := 0; i2 :=0; with Qrytmp do begin first; while not eof do begin i1 :=RecNo Div PrintLines; i2 :=RecNo Mod PrintLines; if i2 =0 then i :=i1 else i :=i1 +1;
with DPrintQry do begin append; For j :=1 to GetMaskCount(DetFlds, '\') do begin Fld :=GetMaskString(DetFlds, '\', j); FieldByName(Fld).asstring :=Qrytmp.FieldByName(Fld).asstring; end; For j :=1 to GetMaskCount(NumFld, '\') do begin Fld :=GetMaskString(NumFld, '\', j); FieldByName(Fld).asstring :=Qrytmp.FieldByName(Fld).asstring; end;
FieldByName('CurrPage').asstring :=inttostr(i); post; end; next; end; end; //补全N行 For j :=0 to ( (PrintLines -i2) Mod PrintLines ) -1 do begin with DPrintQry do begin append; FieldByName('CurrPage').asstring :=inttostr(i); post; end; end; //设置最大分组页数和打印格式公司标题名称 with DPrintQry do begin first; while not eof do begin edit; FieldByName('PageCount').asstring :=inttostr(i); FieldByName('PrintCompName').asstring :=PrintCompName; Post; next; end; end; //明细数据集加主表字段 with DPrintQry do begin first; while not eof do begin edit; For i :=1 to GetMaskCount(MstFlds, '\') do begin Fld :=GetMaskString(MstFlds, '\', i); FieldByName(Fld).asstring :=MPrintQry.FieldByName(Fld).asstring; end; Post; next; end; end; Qrytmp.Free; end;
FastReport问题整理
页面抬头!
表头
还有明细数据!
FastReport底下有Demo的!
、下面是我写的公共的分页套打代码:
//套打数据集
Procedure PrintPre_Com(vw_mst, vw_Det, FKFld, KFldVal, FDKeyFld, DetFlds, NumFld, MstFlds, DetTable:String;
MPrintQry, DPrintQry :TAdoQuery);
var i, j, i1, i2:integer; Qrytmp :TAdoQuery;
PrintLines :Integer; Sqls ,Fld :String; PrintCompName :string;
begin
PrintLines :=GetPrintLines;//读取结算单打印格式中的行数
PrintCompName :=GetPrintCompName; //打印格式中的公司标题 with MPrintQry do begin close; sql.Text:='Select * from '+vw_mst +' where '+FKFld +'='''+KFldVal+''''; open;end; Qrytmp :=createBatchQry;
with Qrytmp do begin close; sql.Text:='Select * from '+vw_Det+' where '+FKFld +'='''+KFldVal+''' Order By '+FDKeyFld; open;end;
//拼接临时的数据集的Sql。
Sqls :=' Select Re as CurrPage, Re as PageCount, Re as PrintCompName ' ;
For i :=1 to GetMaskCount(DetFlds, '\') do begin
Sqls :=Sqls +',Re as ' +GetMaskString(DetFlds, '\', i);
end; For i :=1 to GetMaskCount(NumFld, '\') do begin
Sqls :=Sqls +',' +GetMaskString(NumFld, '\', i);
end; For i :=1 to GetMaskCount(MstFlds, '\') do begin
Sqls :=Sqls +', Re as ' +GetMaskString(MstFlds, '\', i);
end;
Sqls :=Sqls +' from ' +DetTable +' where 1=2 ';
with DPrintQry do begin close; sql.Text :=Sqls; open; end; i := 0; i2 :=0;
with Qrytmp do begin
first;
while not eof do begin
i1 :=RecNo Div PrintLines;
i2 :=RecNo Mod PrintLines;
if i2 =0 then i :=i1
else i :=i1 +1;
with DPrintQry do begin
append;
For j :=1 to GetMaskCount(DetFlds, '\') do begin
Fld :=GetMaskString(DetFlds, '\', j);
FieldByName(Fld).asstring :=Qrytmp.FieldByName(Fld).asstring;
end; For j :=1 to GetMaskCount(NumFld, '\') do begin
Fld :=GetMaskString(NumFld, '\', j);
FieldByName(Fld).asstring :=Qrytmp.FieldByName(Fld).asstring;
end;
FieldByName('CurrPage').asstring :=inttostr(i);
post;
end;
next;
end;
end; //补全N行
For j :=0 to ( (PrintLines -i2) Mod PrintLines ) -1 do begin
with DPrintQry do begin
append; FieldByName('CurrPage').asstring :=inttostr(i); post;
end;
end; //设置最大分组页数和打印格式公司标题名称
with DPrintQry do begin
first;
while not eof do begin
edit;
FieldByName('PageCount').asstring :=inttostr(i);
FieldByName('PrintCompName').asstring :=PrintCompName;
Post; next;
end;
end; //明细数据集加主表字段
with DPrintQry do begin
first;
while not eof do begin
edit;
For i :=1 to GetMaskCount(MstFlds, '\') do begin
Fld :=GetMaskString(MstFlds, '\', i);
FieldByName(Fld).asstring :=MPrintQry.FieldByName(Fld).asstring;
end;
Post; next;
end;
end; Qrytmp.Free;
end;