如何实现报表的横向打印?(100分)

  • 主题发起人 主题发起人 jeoblack
  • 开始时间 开始时间
J

jeoblack

Unregistered / Unconfirmed
GUEST, unregistred user!
报表中要打印一张Table里的东东,Table很大,横向的列标题在一页里放不下,要放很多页,实现打印的时候要先把横向的列标题全部打印完,
具体说不太清楚,举个例子:
A B C D |E F G
11 12 13 14 |15 16 17 AA | BB
21 22 23 24 |25 26 27 |
--------------------------- -----|----
31 32 33 34 |35 36 37 CC | DD
41 42 43 44 |45 46 47 |
比如现在A,B,C,D,E,F,G是列标题,数字是每列下的具体内容横线和竖线表示分页,也就是现在打印需要4张纸,分别是AA,BB,CC,DD。我现在的要求是,从AA开始打印,然后是BB,CC,DD,就是先把横向的打印完再打印下一个横向。
具体的你可以查看EXCEL中“文件”下拉菜单中“页面设置”中“工作表”中的“打印顺序”。就和那个一样。
我不要你做好的EXE文件,而要对做这个东东时进行的分析,还有控件的设置和源代码之类的。
谢谢帮忙!~
 
用ole来控制excel不好吗?
 
我们导师规定这样做的
 
我觉得你要是用QReport的话,只能先把AA打印完后再打BB,然后再打CC
可能做不到你说的那样
如果直接控制打印机就可以做到
用Tprinter这个类来实现,但编程比较复杂,需要一条记录一条记录的取出来
再写到打印机上去,还一点一点的算出每一张纸可以打印的宽度,超出部分放在下一张纸打印
可参考一下Tprinter的例子,
 
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls, QRCtrls, QuickRpt, ExtCtrls,
DBTables;
type
TForm1 = class(TForm)
ADODataSet1: TADODataSet;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
QuickRep1: TQuickRep;
QRGroup1: TQRGroup;
ColumnHeaderBand1: TQRBand;
DetailBand1: TQRBand;
QRDBText1: TQRDBText;
QRDBText2: TQRDBText;
QRDBText3: TQRDBText;
QRDBText4: TQRDBText;
QRLabel1: TQRLabel;
QRLabel2: TQRLabel;
QRLabel3: TQRLabel;
PageFooterBand1: TQRBand;
ADODataSet2: TADODataSet;
ADODataSet3: TADODataSet;
DataSource2: TDataSource;
DBGrid2: TDBGrid;
QRLabel4: TQRLabel;
QRLabel5: TQRLabel;
Table1: TTable;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure QRLabel1Print(sender: TObject;
var Value: string);
procedure QRLabel2Print(sender: TObject;
var Value: string);
procedure QRLabel3Print(sender: TObject;
var Value: string);
procedure QRLabel4Print(sender: TObject;
var Value: string);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i, j: integer;
begin


ADODataSet1.FieldDefs.Clear;
ADODataSet1.FieldDefs.Add('A', ftstring, 20, false);
ADODataSet1.FieldDefs.Add('B', ftstring, 20, false);
ADODataSet1.FieldDefs.Add('C', ftstring, 20, false);
ADODataSet1.FieldDefs.Add('D', ftstring, 20, false);
ADODataSet1.FieldDefs.Add('E', ftstring, 20, false);
ADODataSet1.FieldDefs.Add('F', ftstring, 20, false);
ADODataSet1.FieldDefs.Add('G', ftstring, 20, false);
ADODataSet1.CreateDataSet;
ADODataSet1.Open;
ADODataSet1.Append;
for i := 1 to 50do
begin
ADODataSet1.Append;
for j := 0 to ADODataSet1.FieldCount - 1do
ADODataSet1.Fields[j].AsString := format('%d_%d', [i, j]);
end;
ADODataSet1.Post;
ADODataSet1.First;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
myRow, NowPage, NowRow, i: integer;
begin
myRow := 30;
//每页多少行 ,手工设置 。如果程序自动获得 ,就要换一种写法
NowPage := 1;
NowRow := 0;
ADODataSet2.Close;
ADODataSet2.FieldDefs.Clear;
ADODataSet2.FieldDefs.Add('myFooter', ftstring, 50, false);
ADODataSet2.FieldDefs.Add('flag', ftstring, 50, false);
ADODataSet2.FieldDefs.Add('v1', ftstring, 20, false);
ADODataSet2.FieldDefs.Add('v2', ftstring, 20, false);
ADODataSet2.FieldDefs.Add('v3', ftstring, 20, false);
ADODataSet2.FieldDefs.Add('v4', ftstring, 20, false);
ADODataSet2.CreateDataSet;
ADODataSet2.Open;
//若为bde
//则用
// Table1.TableName:='C:/Temp2.dat';
// Table1.FieldDefs.Add('myFooter', ftstring, 50, false);
// Table1.CreateTable;
// Table1.Open;
//或 用临时表
ADODataSet3.FieldDefs := ADODataSet2.FieldDefs;
ADODataSet3.CreateDataSet;
ADODataSet3.Open;
ADODataSet1.First;
while not ADODataSet1.Eofdo
begin

NowRow := NowRow + 1;
ADODataSet2.Append;
ADODataSet2.FieldByName('myFooter').AsString := format('第%d页 第%d联', [NowPage, 1]);
ADODataSet2.FieldByName('flag').AsString := '1';
ADODataSet2.FieldByName('v1').AsString := ADODataSet1.Fieldbyname('A').AsString;
ADODataSet2.FieldByName('v2').AsString := ADODataSet1.Fieldbyname('B').AsString;
ADODataSet2.FieldByName('v3').AsString := ADODataSet1.Fieldbyname('C').AsString;
ADODataSet2.FieldByName('v4').AsString := ADODataSet1.Fieldbyname('D').AsString;
ADODataSet2.Post;
ADODataSet3.Append;
ADODataSet3.FieldByName('myFooter').AsString := format('第%d页 第%d联', [NowPage, 2]);
ADODataSet3.FieldByName('flag').AsString := '2';
ADODataSet3.FieldByName('v1').AsString := ADODataSet1.Fieldbyname('E').AsString;
ADODataSet3.FieldByName('v2').AsString := ADODataSet1.Fieldbyname('F').AsString;
ADODataSet3.FieldByName('v3').AsString := ADODataSet1.Fieldbyname('G').AsString;
ADODataSet3.FieldByName('v4').AsString := '-';
ADODataSet3.Post;
if NowRow = myRow then
begin

ADODataSet3.First;
while not ADODataSet3.Eofdo
begin
ADODataSet2.Append;
for i := 0 to ADODataSet2.FieldCount - 1do
ADODataSet2.Fields.Value := ADODataSet3.Fields.Value;
ADODataSet2.Post;
ADODataSet3.Delete;
end;
NowPage := NowPage + 1;
NowRow := 0;
end;
ADODataSet1.next;
end;
if NowRow <> 0 then
begin
ADODataSet3.First;
while not ADODataSet3.Eofdo
begin
ADODataSet2.Append;
for i := 0 to ADODataSet2.FieldCount - 1do
ADODataSet2.Fields.Value := ADODataSet3.Fields.Value;
ADODataSet2.Post;
ADODataSet3.Delete;
end;
NowPage := NowPage + 1;
NowRow := 0;
end;
QuickRep1.Preview;
end;

procedure TForm1.QRLabel1Print(sender: TObject;
var Value: string);
begin
if ADODataSet2.FieldByName('flag').AsString = '1' then
Value := 'A'
else
Value := 'E';
QRLabel5.Caption := ADODataSet2.FieldByName('myFooter').AsString;
end;

procedure TForm1.QRLabel2Print(sender: TObject;
var Value: string);
begin
if ADODataSet2.FieldByName('flag').AsString = '1' then
Value := 'B'
else
Value := 'F';
end;

procedure TForm1.QRLabel3Print(sender: TObject;
var Value: string);
begin
if ADODataSet2.FieldByName('flag').AsString = '1' then
Value := 'C'
else
Value := 'G';
end;

procedure TForm1.QRLabel4Print(sender: TObject;
var Value: string);
begin
if ADODataSet2.FieldByName('flag').AsString = '1' then
Value := 'D'
else
Value := '-';
end;

end.



object Form1: TForm1
Left = 192
Top = 107
Width = 611
Height = 465
VertScrollBar.Position = 140
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
Scaled = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object DBGrid1: TDBGrid
Left = 0
Top = -140
Width = 794
Height = 120
Align = alTop
DataSource = DataSource1
TabOrder = 0
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object Button1: TButton
Left = 8
Top = -4
Width = 75
Height = 25
Caption = 'Button'
TabOrder = 1
OnClick = Button1Click
end
object QuickRep1: TQuickRep
Left = 0
Top = 140
Width = 794
Height = 321
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
DataSet = ADODataSet2
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'Arial'
Font.Style = []
Functions.Strings = (
'PAGENUMBER'
'COLUMNNUMBER'
'REPORTTITLE')
Functions.DATA = (
'0'
'0'
'''''')
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 QRGroup1: TQRGroup
Left = 38
Top = 67
Width = 718
Height = 3
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
AlignToBottom = False
Color = clWhite
ForceNewColumn = True
ForceNewPage = False
Size.Values = (
7.9375
1899.70833333333)
Expression = 'ADODataSet2.MyFooter'
Master = QuickRep1
ReprintOnNewPage = False
end
object ColumnHeaderBand1: TQRBand
Left = 38
Top = 38
Width = 718
Height = 29
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 = (
76.7291666666667
1899.70833333333)
BandType = rbColumnHeader
object QRLabel1: TQRLabel
Left = 48
Top = 8
Width = 58
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
127
21.1666666666667
153.458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = 'QRLabel1'
Color = clWhite
OnPrint = QRLabel1Print
Transparent = False
WordWrap = True
FontSize = 10
end
object QRLabel2: TQRLabel
Left = 144
Top = 8
Width = 58
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
381
21.1666666666667
153.458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = 'QRLabel2'
Color = clWhite
OnPrint = QRLabel2Print
Transparent = False
WordWrap = True
FontSize = 10
end
object QRLabel3: TQRLabel
Left = 240
Top = 8
Width = 58
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
635
21.1666666666667
153.458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = 'QRLabel3'
Color = clWhite
OnPrint = QRLabel3Print
Transparent = False
WordWrap = True
FontSize = 10
end
object QRLabel4: TQRLabel
Left = 336
Top = 8
Width = 58
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
889
21.1666666666667
153.458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = 'QRLabel4'
Color = clWhite
OnPrint = QRLabel4Print
Transparent = False
WordWrap = True
FontSize = 10
end
end
object DetailBand1: TQRBand
Left = 38
Top = 70
Width = 718
Height = 28
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 = (
74.0833333333333
1899.70833333333)
BandType = rbDetail
object QRDBText1: TQRDBText
Left = 48
Top = 5
Width = 13
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
127
13.2291666666667
34.3958333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADODataSet2
DataField = 'v1'
Transparent = False
WordWrap = True
FontSize = 10
end
object QRDBText2: TQRDBText
Left = 144
Top = 5
Width = 13
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
381
13.2291666666667
34.3958333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADODataSet2
DataField = 'v2'
Transparent = False
WordWrap = True
FontSize = 10
end
object QRDBText3: TQRDBText
Left = 240
Top = 5
Width = 13
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
635
13.2291666666667
34.3958333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADODataSet2
DataField = 'v3'
Transparent = False
WordWrap = True
FontSize = 10
end
object QRDBText4: TQRDBText
Left = 337
Top = 5
Width = 13
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
891.645833333333
13.2291666666667
34.3958333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Color = clWhite
DataSet = ADODataSet2
DataField = 'v4'
Transparent = False
WordWrap = True
FontSize = 10
end
end
object PageFooterBand1: TQRBand
Left = 38
Top = 98
Width = 718
Height = 146
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 = (
386.291666666667
1899.70833333333)
BandType = rbPageFooter
object QRLabel5: TQRLabel
Left = 48
Top = 8
Width = 58
Height = 17
Frame.Color = clBlack
Frame.DrawTop = False
Frame.DrawBottom = False
Frame.DrawLeft = False
Frame.DrawRight = False
Size.Values = (
44.9791666666667
127
21.1666666666667
153.458333333333)
Alignment = taLeftJustify
AlignToBand = False
AutoSize = True
AutoStretch = False
Caption = 'QRLabel5'
Color = clWhite
Transparent = False
WordWrap = True
FontSize = 10
end
end
end
object DBGrid2: TDBGrid
Left = 8
Top = 28
Width = 553
Height = 105
DataSource = DataSource2
TabOrder = 3
TitleFont.Charset = DEFAULT_CHARSET
TitleFont.Color = clWindowText
TitleFont.Height = -11
TitleFont.Name = 'MS Sans Serif'
TitleFont.Style = []
end
object ADODataSet1: TADODataSet
Parameters = <>
Left = 24
Top = 48
end
object DataSource1: TDataSource
DataSet = ADODataSet1
Left = 64
Top = 48
end
object ADODataSet2: TADODataSet
Parameters = <>
Left = 160
Top = 208
end
object ADODataSet3: TADODataSet
Parameters = <>
Left = 160
Top = 248
end
object DataSource2: TDataSource
DataSet = ADODataSet2
Left = 200
Top = 208
end
object Table1: TTable
Left = 192
Top = 16
end
end


来自:hfghfghfg, 时间:2003-5-18 11:35:00, ID:1871413 | 编辑
给多少分都行 是真的吗?
我可以画各种报表。
下面是效果:

A B C D
1_0 1_1 1_2 1_3
2_0 2_1 2_2 2_3
3_0 3_1 3_2 3_3
4_0 4_1 4_2 4_3
5_0 5_1 5_2 5_3
6_0 6_1 6_2 6_3
7_0 7_1 7_2 7_3
8_0 8_1 8_2 8_3
9_0 9_1 9_2 9_3
10_0 10_1 10_2 10_3
11_0 11_1 11_2 11_3
12_0 12_1 12_2 12_3
13_0 13_1 13_2 13_3
14_0 14_1 14_2 14_3
15_0 15_1 15_2 15_3
16_0 16_1 16_2 16_3
17_0 17_1 17_2 17_3
18_0 18_1 18_2 18_3
19_0 19_1 19_2 19_3
20_0 20_1 20_2 20_3
21_0 21_1 21_2 21_3
22_0 22_1 22_2 22_3
23_0 23_1 23_2 23_3
24_0 24_1 24_2 24_3
25_0 25_1 25_2 25_3
26_0 26_1 26_2 26_3
27_0 27_1 27_2 27_3
28_0 28_1 28_2 28_3
29_0 29_1 29_2 29_3
30_0 30_1 30_2 30_3
第1页 第1联

E F G -
1_4 1_5 1_6 -
2_4 2_5 2_6 -
3_4 3_5 3_6 -
4_4 4_5 4_6 -
5_4 5_5 5_6 -
6_4 6_5 6_6 -
7_4 7_5 7_6 -
8_4 8_5 8_6 -
9_4 9_5 9_6 -
10_4 10_5 10_6 -
11_4 11_5 11_6 -
12_4 12_5 12_6 -
13_4 13_5 13_6 -
14_4 14_5 14_6 -
15_4 15_5 15_6 -
16_4 16_5 16_6 -
17_4 17_5 17_6 -
18_4 18_5 18_6 -
19_4 19_5 19_6 -
20_4 20_5 20_6 -
21_4 21_5 21_6 -
22_4 22_5 22_6 -
23_4 23_5 23_6 -
24_4 24_5 24_6 -
25_4 25_5 25_6 -
26_4 26_5 26_6 -
27_4 27_5 27_6 -
28_4 28_5 28_6 -
29_4 29_5 29_6 -
30_4 30_5 30_6 -
第1页 第2联

A B C D
31_0 31_1 31_2 31_3
32_0 32_1 32_2 32_3
33_0 33_1 33_2 33_3
34_0 34_1 34_2 34_3
35_0 35_1 35_2 35_3
36_0 36_1 36_2 36_3
37_0 37_1 37_2 37_3
38_0 38_1 38_2 38_3
39_0 39_1 39_2 39_3
40_0 40_1 40_2 40_3
41_0 41_1 41_2 41_3
42_0 42_1 42_2 42_3
43_0 43_1 43_2 43_3
44_0 44_1 44_2 44_3
45_0 45_1 45_2 45_3
46_0 46_1 46_2 46_3
47_0 47_1 47_2 47_3
48_0 48_1 48_2 48_3
49_0 49_1 49_2 49_3
50_0 50_1 50_2 50_3
第2页 第1联

E F G -
31_4 31_5 31_6 -
32_4 32_5 32_6 -
33_4 33_5 33_6 -
34_4 34_5 34_6 -
35_4 35_5 35_6 -
36_4 36_5 36_6 -
37_4 37_5 37_6 -
38_4 38_5 38_6 -
39_4 39_5 39_6 -
40_4 40_5 40_6 -
41_4 41_5 41_6 -
42_4 42_5 42_6 -
43_4 43_5 43_6 -
44_4 44_5 44_6 -
45_4 45_5 45_6 -
46_4 46_5 46_6 -
47_4 47_5 47_6 -
48_4 48_5 48_6 -
49_4 49_5 49_6 -
50_4 50_5 50_6 -
第2页 第2联


 
后退
顶部