怎样打印出具有类似于powerbuilder中crosstab风格的报表?(60分)

  • 主题发起人 主题发起人 lane
  • 开始时间 开始时间
L

lane

Unregistered / Unconfirmed
GUEST, unregistred user!
我现在要设计一张打印报表,看过demo的例子后发现只能自上而下一行行地将记录内容打印在detail栏,但我希望能打印出具有类似于powerbuilder中crosstab风格的报表.举例如下:
数据库中有表 A ,有三个字段: A1(用户名) A2(日期) A3(购买产品数量)
要求报表形式为: 12月1号 12月2号 12月3号
用户甲 10件 7件 9件
用户乙 50件 18件 40件
...... ... ... ...
甚感焦急!请各位大虾尽快赐教,谢了!
 
用QReport好象无法解决.
只有用第三方控件或者自己编写了 :(

我有一个想法不知可不可行:
1. 用程序生成一个按打印的格式排列的Stringgrid(应该不难)
把这个stringgrid想法送到打印机
编程一行一列地画到printer.canvas上(笨且慢的方法, 但能解决问题)

2.生成一个TBitmap, 例如: bmp:=TBitmap.Create;
把bmp.height, bmp.width置成stringgrid.height, stringgrid.width
bmp.canvas.handle:=stringgrid.canvas.handle;
程序生成stringgrid的内容
printer.begin
doc;
printer.canvas.draw(x,y,bmp);
printer.enddoc;
不知是否可行.
 
Try Decision Cube can show present data like that. But you need to
program the printing part you self.

I am not very sure that Query builder cando
or not.

Access's query wizard can create that kind of query.
 
1. 统计出你的日期数(栏目数)
2. 利用在程序中定义数据库结构,生成一个新数据库(一般为Paradox),
新数据库中有这些日期字段。
3. 利用SQL和Batchmove将数据拷贝到相应的字段。
4. 在通过QReort输出。

这个方法我已使用,效果不错。
 
对于该问题,尔与我同感也!!!我也非常苦恼!
以前在DOS下PASCAL编程时,都用制表符的方法,
在WINDOW中,似乎只能用CANVAS.LINE一根一根画了,
不过,我也编了一个将中文制表符用CANVAS.LINE画出的程序,
感兴趣否?
 
看样子你可能要自己写了,我这有个DELPHI的站点,
可能有你想要的东西!<A HREF="http://www.global.co.za/~jmcalitz/homepage.htm">http://www.global.co.za/~jmcalitz/</A>里面有个超级打印控件,如果在没有,那
你必须自己动手了.*_*
 
unit cross32;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Qrctrls, quickrpt, DB, DBTables, ExtCtrls;

type
Tfrmxtab = class(TForm)
QuickRep1: TQuickRep;
Query1: TQuery;
QRSubDetail1: TQRSubDetail;
QRDBText1: TQRDBText;
QRDBText2: TQRDBText;
QRGroup1: TQRGroup;
QRLabel1: TQRLabel;
QRLabel2: TQRLabel;
QRSubDetail2: TQRSubDetail;
QRLabel3: TQRLabel;
Query1Customers: TIntegerField;
Query1State: TStringField;
QRBand1: TQRBand;
TitleBand1: TQRBand;
QRMemo1: TQRMemo;
QRLabel4: TQRLabel;
QRLabel5: TQRLabel;
QRLabel6: TQRLabel;
procedure QRSubDetail2BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
procedure QuickRep1BeforePrint(Sender: TQuickRep;
var PrintReport: Boolean);
procedure QRBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
{ Define a matix array for 50 states with 2 columns }
Matrix: array [1..50,1..2] of string;
qrlStates,
qrlCustomers: array [0..10] of TQRLabel;
Row: integer;
{ Global variable to track the current row in the matrix}
end;


var
frmxtab: Tfrmxtab;

implementation

{$R *.DFM}

procedure Tfrmxtab.QRSubDetail2BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
begin

{
Wedo
n't print this band out, but we need this event to populate our array
with the contents of the dataset.

This is not the only method fordo
ing this. You could populate the array
before you run the report and use BeforePrint event of the band to just
output the data.
}

PrintBand := False;

{
For the purposes of this example, we are limiting the report to only
the first 10 states returned in the dataset
}

if Row < 10 then

begin

Inc(Row);

{
Now we fill our array, each state gets it's own row. We are basicly
building a copy of the dataset in memory, because it's faster to navigate
the array whendo
ng a crosstab report.
}
Matrix[row,1] := IntToStr(Query1Customers.Value);
Matrix[row,2] := Query1State.Value;
end;

end;


procedure Tfrmxtab.QuickRep1BeforePrint(Sender: TQuickRep;
var PrintReport: Boolean);
begin

Row := 0;
end;


procedure Tfrmxtab.QRBand1BeforePrint(Sender: TQRCustomBand;
var PrintBand: Boolean);
var
nIdx: integer;
begin

{
Now we "rotate" the data to ouput the crosstab report
}
qrlStates[0].Caption := 'States:';
qrlCustomers[0].Caption := 'Customers:';
for nIdx := 1 to 10do

begin

qrlStates[nIdx].Caption := Matrix[nIdx,2];
qrlCustomers[nIdx].Caption := Matrix[nIdx,1];

if qrlStates[nIdx].Caption = '' then

qrlStates[nIdx].Caption := 'N/A';
end;

end;


procedure Tfrmxtab.FormCreate(Sender: TObject);
var
MyWidth,
nIdx: integer;
begin


MyWidth := Trunc(QRBand1.Width / 11);
for nIdx := 0 to 10do

begin

qrlStates[nIdx] := TQRLabel.Create(frmxtab);
qrlCustomers[nIdx] := TQRLabel.Create(frmxtab);

with qrlStates[nIdx]do

begin

Parent := QRBand1;
AlignToBand := False;
AutoSize := False;
AutoStretch := False;
Color := clWhite;
Top := 64;
if nIdx = 0 then

begin

Left := 0;
Width := MyWidth+6;
end
else

begin

Left := MyWidth * nIdx + 6;
Width := MyWidth - 6;
end;

Font.Style := [fsItalic,fsBold];

qrlCustomers[nIdx].Parent := qrlStates[nIdx].Parent;
qrlCustomers[nIdx].AligntoBand := qrlStates[nIdx].AligntoBand;
qrlCustomers[nIdx].AutoSize := qrlStates[nIdx].AutoSize;
qrlCustomers[nIdx].AutoStretch := qrlStates[nIdx].AutoStretch;
qrlCustomers[nIdx].Color := qrlStates[nIdx].Color;
qrlCustomers[nIdx].Top := qrlStates[nIdx].Top + qrlStates[nIdx].Height + 10;
qrlCustomers[nIdx].Left := qrlStates[nIdx].Left;
qrlCustomers[nIdx].Width := qrlStates[nIdx].Width;

end
end;

end;


procedure Tfrmxtab.FormDestroy(Sender: TObject);
var
nIdx: integer;
begin


for nIdx := 0 to 10do

begin

qrlStates[nIdx].Free;
qrlCustomers[nIdx].Free;
end;

end;


end.

 
用Decision Cube可以很轻松地实现, 再下载一个DecisionCube的打印控件
<a href="http://www.zhanglong.com/softwork/components/dcuberep.zip">DCubeRep.Zip</a>即可搞定
 
请huizhang大虾解释一下具体怎样用DecisionCube来实现。DecisionCube的打印控
件我已下载,该怎样使用?
 
请huizhang大虾解释一下具体怎样用DecisionCube来实现。DecisionCube的打印控
件我已下载,该怎样使用?
 
请问huizhang大虾,我下载了QCubeRep的控件,并在install component中
install并compile了,然后将下载的文件拷入/lib目录下.我在一个form
上放了一个Qcuberep,并指定了cubegrid,编译正常通过,但运行时出现:
raised exception class EReadError with message " Propertydo
es not
exist " , Process stopped 的错误,去掉该控件则运行正常,该如何解决?
另,此控件该如何使用?多谢指点!
 
Sorry keep you waiting, I can not access the web for tree days because
upper level site problems.

I havent get a chance to look at that report component. After I have
try it, I will give you a answer.

Have you tried that DecisionCube? If not, simplly create a new
DecisionCube Application use the app wizard.
 
QCubeRep应该保留在它的安装目录, 如果你安装后有把他移动到lib目录恐怕就找不
到了. 我试了一下这个QCubeRep, 还算可以, 能够预览DecisionCube得表格
 
I have tried to install from /delphi 3/lib with source file already copied
in this directory , the same problem raise when I try to run the
compiled project.
do
es thedo
wnload zip file contains only two files:cuberep.pas and
cuberep.dfm?
When I try to open cuberep.pas merely, a dialog box appear telling
me that :
"Error reading frmCubeReport.OldCreateOrder:Propertydo
es
not exist. Ignor the error and continue?....."
I reply "ingor" and then
another dialog box appear:
"Error reading QuickRep1.Functions.Strings:Propertydo
es
not exist. Ignor the error and continue?....."
I reply "ingor" again and then
:
"Error reading QuickRep1.Functions.DATA:Propertydo
es
not exist. Ignor the error and continue?....."
I reply "ignor" , finally the "frmCubeReport" represent to me.
So I am confused by the error message. The Delphi I use is
Version 3.0 for Client/Server Suite. Can you tell me what the
problem is?
 
Please check the file size is :
cuberep.pas 11,865
cuberep.dfm 4,201
 

Similar threads

D
回复
0
查看
941
DelphiTeacher的专栏
D
D
回复
0
查看
880
DelphiTeacher的专栏
D
D
回复
0
查看
956
DelphiTeacher的专栏
D
D
回复
0
查看
785
DelphiTeacher的专栏
D
后退
顶部