打印字段太多,用换行来处理;
1.窗体上方一个QuickRep1 ,一个TitleBand1,一个DetailBand1
2.代码
var
iLeft,i,tleft,n : integer;
QRShape1,QRShape2 : TQRShape;
is_next : boolean;
begin
if not Assigned(dbGrid1.DataSource) then Exit;
if not Assigned(dbGrid1.DataSource.DataSet) then Exit;
//---------------------------------------------------------
QRShape1 := TQRShape.Create(DetailBand1);//创建一个矩形 ,一个矩形方一个的工资
with QRShape1 do
begin
Parent := DetailBand1;
Left := 0;
top := 0;
Width := DetailBand1.Width;
height := 50;
end;
DetailBand1.Height := 70;
//-----------------------
iLeft := 6;
tleft := 0;
n := 0;
is_next := false;
for I := 0 to dbgrid1.Columns.Count-1 do
begin
if dbgrid1.Columns.Items[I].Visible then
begin
tLeft := iLeft + dbgrid1.Columns.Items[I].Width;
if tLeft > DetailBand1.ClientWidth then
is_next := true;
if is_next then
begin
QRShape1.Height := 50 + QRShape1.Height;
DetailBand1.Height := 50 + DetailBand1.Height;
n := n + 40;
iLeft := 6;
tleft := 0;
QRShape2 := TQRShape.Create(DetailBand1);//要换行时创建线条,作为分隔线;
with QRShape2 do
begin
Parent := DetailBand1;
Left := 0;
top := n + 11;
Width := DetailBand1.Width;
height := 1;
end;
is_next := false; //
end;
//---------------
with TQRLabel.Create(DetailBand1) do
begin
Parent := DetailBand1;
Left := iLeft;
Width := dbgrid1.Columns.Items[I].Width;
Caption := dbgrid1.Columns.Items[I].Title.Caption;
Alignment := dbgrid1.Columns.Items[I].Title.Alignment;
Top := Height + 2 + n;
end;
//TQRDBText--------------------
with TQRDBText.Create(DetailBand1) do
begin
Parent := DetailBand1;
Left := ileft;
Width := dbgrid1.Columns.Items[I].Width;
ileft := ileft + Width;
DataSet := dbgrid1.DataSource.DataSet;
DataField := dbgrid1.Columns.Items[i].FieldName;
Alignment := dbgrid1.Columns.Items[I].Title.Alignment;
Top := Height + 20 + n;
end;
end
else continue;
end;
{ QRCompositeReport2.Prepare;
QRCompositeReport2.Preview; }
QuickRep1.Preview;