给你一段动态打印的源代吗
//窗体文件
object frmSysPrint: TfrmSysPrint
Left = -4
Top = -4
Width = 808
Height = 608
Caption = 'frmSysPrint'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Scaled = False
PixelsPerInch = 96
TextHeight = 13
object QuickRep1: TQuickRep
Left = 8
Top = 16
Width = 794
Height = 1123
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = '宋体'
Font.Style = []
Functions.Strings = (
'PAGENUMBER'
'COLUMNNUMBER'
'REPORTTITLE')
Functions.DATA = (
'0'
'0'
'''''')
OnPreview = QuickRep1Preview
Options = [FirstPageHeader, LastPageFooter]
Page.Columns = 1
Page.Orientation = poPortrait
Page.PaperSize = A4
Page.Values = (
100
2970
100
2100
100
100
0)
PrinterSettings.Copies = 1
PrinterSettings.Duplex = False
PrinterSettings.FirstPage = 0
PrinterSettings.LastPage = 0
PrinterSettings.OutputBin = Auto
PrintIfEmpty = True
SnapToGrid = True
Units = MM
Zoom = 100
object DetailBand: TQRBand
Left = 38
Top = 146
Width = 718
Height = 28
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = True
Frame.DrawLeft = True
Frame.DrawRight = True
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
74.0833333333333
1899.70833333333)
BandType = rbDetail
end
object TitleBand: TQRBand
Left = 38
Top = 78
Width = 718
Height = 40
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
105.833333333333
1899.70833333333)
BandType = rbTitle
object Title: TQRLabel
Left = 117
Top = 10
Width = 51
Height = 20
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
52.9166666666667
309.5625
26.4583333333333
134.9375)
Alignment = taCenter
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = 'Title'
Color = clWhite
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -17
Font.Name = '宋体'
Font.Style = [fsBold]
ParentFont = False
Transparent = False
WordWrap = True
FontSize = 13
end
end
object ColHeaderBand: TQRBand
Left = 38
Top = 118
Width = 718
Height = 28
Frame.Color = clBlack
Frame.DrawTop = True
Frame.DrawBottom = True
Frame.DrawLeft = True
Frame.DrawRight = True
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
74.0833333333333
1899.70833333333)
BandType = rbColumnHeader
end
object PageHeaderBand: TQRBand
Left = 38
Top = 38
Width = 718
Height = 40
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
105.833333333333
1899.70833333333)
BandType = rbPageHeader
object QRLabel1: TQRLabel
Left = 608
Top = 15
Width = 92
Height = 14
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
37.0416666666667
1608.66666666667
39.6875
243.416666666667)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = '新闻带管理系统'
Color = clWhite
Transparent = False
WordWrap = True
FontSize = 10
end
object QRShape1: TQRShape
Left = 608
Top = 31
Width = 94
Height = 1
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
2.64583333333333
1608.66666666667
82.0208333333333
248.708333333333)
Shape = qrsRectangle
end
end
object PageFooterBand: TQRBand
Left = 38
Top = 174
Width = 718
Height = 40
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = False
ForceNewPage = False
Size.Values = (
105.833333333333
1899.70833333333)
BandType = rbPageFooter
object QRSysData1: TQRSysData
Left = 631
Top = 11
Width = 50
Height = 14
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
37.0416666666667
1669.52083333333
29.1041666666667
132.291666666667)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
Color = clWhite
Data = qrsPageNumber
Transparent = False
FontSize = 10
end
object QRLabel2: TQRLabel
Left = 605
Top = 11
Width = 14
Height = 14
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
37.0416666666667
1600.72916666667
29.1041666666667
37.0416666666667)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = '第'
Color = clWhite
Transparent = False
WordWrap = True
FontSize = 10
end
object QRLabel3: TQRLabel
Left = 654
Top = 11
Width = 14
Height = 14
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
37.0416666666667
1730.375
29.1041666666667
37.0416666666667)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = '页'
Color = clWhite
Transparent = False
WordWrap = True
FontSize = 10
end
object QRShape2: TQRShape
Left = 604
Top = 28
Height = 1
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
2.64583333333333
1598.08333333333
74.0833333333333
171.979166666667)
Shape = qrsRectangle
end
object QRLabel4: TQRLabel
Left = 8
Top = 14
Width = 66
Height = 14
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
37.0416666666667
21.1666666666667
37.0416666666667
174.625)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = '打印日期:'
Color = clWhite
Transparent = False
WordWrap = True
FontSize = 10
end
object QRSysData2: TQRSysData
Left = 79
Top = 14
Width = 78
Height = 14
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
37.0416666666667
209.020833333333
37.0416666666667
206.375)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
Color = clWhite
Data = qrsDateTime
Transparent = False
FontSize = 10
end
end
end
end
//源代码
//打印dxdbGrid
procedure PrintDxGrid(dxGrid: TdxDBGrid;
ATitle: string);
const max = 30;
var
BandHeight: Integer;
ColWidth: Integer;
ColLeft: Integer;
ColTop: Integer;
ColFieldName: string;
ColCaption: string;
GridDataSet: TDataSet;
I: Integer;
Count: Integer;
qrlable: array[1..max] of TQRLabel;
qrdbtext: array[1..max] of TQRDBText;
qrshapeA: array[1..max] of TQRShape;
qrshapeB: array[1..max] of TQRShape;
bookmark : TBookmark;
begin
bookmark := dxGrid.DataSource.DataSet.GetBookmark;
dxGrid.DataSource.DataSet.DisableControls;
try
with frmSysPrintdo
begin
Title.Caption := ATitle;
Title.Left := (TitleBand.Width - Title.Width) div 2;
end;
BandHeight := frmSysPrint.DetailBand.Height;
ColTop := (frmSysPrint.DetailBand.Height - 14) div 2;
ColLeft := 0;
GridDataSet := dxGrid.DataSource.DataSet;
Count := 0;
with frmSysPrintdo
begin
//设置qreport的DataSet
QuickRep1.DataSet := GridDataSet;
For I := 0 to dxGrid.ColumnCount - 1do
if I > 29 then
//最多只能打印30列
Break
else
if dxGrid.Columns.Visible then
begin
ColWidth := dxGrid.Columns.Width;
ColCaption := dxGrid.Columns.Caption;
ColFieldName := dxGrid.Columns.FieldName;
//创建列头
Count := Count + 1;
qrlable[Count] := TQRLabel.Create(nil);
with qrlable[Count]do
begin
Parent := ColHeaderBand;
AutoSize := False;
Alignment := taCenter;
Left := ColLeft;
Top := ColTop;
Width := ColWidth;
Caption := ColCaption;
end;
//创建列线
qrshapeA[Count] := TQRShape.Create(nil);
with qrshapeA[Count]do
begin
Parent := ColHeaderBand;
Left := ColLeft;
Top := 0;
Width := 1;
Height := BandHeight;
end;
//创建列
qrdbtext[Count] := TQRDBText.Create(nil);
with qrdbtext[Count]do
begin
Parent := DetailBand;
AutoSize := False;
Alignment := taCenter;
Left := ColLeft;
Top := ColTop;
Width := ColWidth;
DataSet := GridDataSet;
DataField := ColFieldName;
end;
//创建列线
qrshapeB[Count] := TQRShape.Create(nil);
with qrshapeB[Count]do
begin
Parent := DetailBand;
Left := ColLeft;
Top := 0;
Width := 1;
Height := BandHeight;
end;
ColLeft := ColLeft + ColWidth;
end;
//end if
QuickRep1.Preview;
//释放动态创建的控件
for I := 1 to Countdo
begin
FreeAndNil(qrlable);
FreeAndNil(qrdbtext);
FreeAndNil(qrshapeA);
FreeAndNil(qrshapeB);
end;
end;
//end with
finally
dxGrid.DataSource.DataSet.GotoBookmark(bookmark);
dxGrid.DataSource.DataSet.FreeBookmark(bookmark);
dxGrid.DataSource.DataSet.EnableControls;
end;
end;
procedure TfrmSysPrint.QuickRep1Preview(Sender: TObject);
begin
with TfrmPreview.Create(Application)do
begin
QRPreview1.QRPrinter := QuickRep1.Printer;
Show;
end;
end;