Delphi 7下如何动态创建Rave报表(100分)

  • 主题发起人 主题发起人 huawei_dfm
  • 开始时间 开始时间
H

huawei_dfm

Unregistered / Unconfirmed
GUEST, unregistred user!
手头的一个程序需要动态创建报表来打印数据,而非像Rave Designer那样事先设计好再
打印,以前Quick Report就可以,我想Rave也应该可以的,只是这几天找相关的资料很难找
,其网站上也没有5.0的文档下载,只有4.0的。更可气的是,Demo例子也就无所谓了,可源
程序pas文件都没有,想看它的类结构都很困难(只能看可怜的Help了)。
 
那你为什么不装上QR继续用呢?呵呵,就会喜新厌旧!
 
我还在用QR呢,但恐怕迟早要用Rave,听听.
 
请问如何在D7上装QR?
 
查看DEMO中的qr的例子所在目录,有详细说明
 
楼上的详细说说好不好?
 
我已经装上了,谢谢。
 
大家帮忙看一下写的这个程序,可以实现单表的简单打印与输出,但是仍有几个问题未解决:
1。如何自动调整列的宽度;
2。字段值如何自动换行显示;
3。使用Rave的类(好像有个TDataIem)如何实现,不要使用OnPrint事件。
unit DataSet2RaveRpt;
interface
uses
Windows, Forms, Classes, Db, Graphics, SysUtils,
RpDefine, RpBase, RpSystem, RpRenderText, RpRenderRTF, RpRenderHTML, RpRenderPDF;
type
TDataSet2RaveRpt = Class(TComponent)
private
FDSRpt: TDataSet;
FRvSys: TRvSystem;
//负责打印的主要Rave控件
FRvPDF: TRvRenderPDF;
FRvHTML: TRvRenderHTML;
FRvRTF: TRvRenderRTF;
FRvText: TRvRenderText;
FCols: Array of Integer;
//记录要打印的数据列在数据集中的位置
FWidths: Array ofdo
uble;
//记录要打印的数据列的宽度
FOldBkMark: TBookMark;
procedure SetMarginLeft(Value:do
uble);
procedure SetMarginTop(Value:do
uble);
procedure SetMarginRight(Value:do
uble);
procedure SetMarginBottom(Value:do
uble);
procedure SetOrientation(Value: TOrientation);
procedure SetTitle(Value: WideString);
procedure Init;
procedure PrintData(Report: TBaseReport);
procedure PrintColHeader(Report: TBaseReport);
procedure MyOnPrint(Sender: TObject);
procedure MyOnNewPage(Sender: TObject);
public
Constructor Create(AOwner: TComponent);
override;
Destructor Destroy;
override;
property DSRpt: TDataSet read FDSRpt write FDSRpt;
property MarginLeft:do
uble write SetMarginLeft;
property MarginTop:do
uble write SetMarginTop;
property MarginRight:do
uble write SetMarginRight;
property MarginBottom:do
uble write SetMarginBottom;
property Orientation: TOrientation write SetOrientation;
property Title: WideString write SetTitle;
procedure Print;
end;

implementation
constructor TDataSet2RaveRpt.Create(AOwner: TComponent);
begin
inherited;
FRvSys := TRvSystem.Create(AOwner);
FRvSys.DefaultDest := rdPreview;
FRvSys.SystemFiler.StatusFormat := '正在生成第%p页...';
FRvSys.SystemPreview.FormState := wsMaximized;
FRvSys.SystemPrinter.StatusFormat := '正在打印第%p页...';
FRvSys.SystemPrinter.Title := '数据报表';
FRvSys.TitleSetup := '输出设置';
FRvSys.TitlePreview := '数据报表';
FRvSys.TitleStatus := '报表状态';
FRvSys.OnPrint := MyOnPrint;
FRvSys.OnNewPage := MyOnNewPage;
FRvPDF := TRvRenderPDF.Create(Self);
FRvPDF.DocInfo.Creator := '';
FRvPDF.DocInfo.Producer := '';
FRvHTML := TRvRenderHTML.Create(Self);
FRvHTML.DisplayName := 'Web网页(HTML)';
FRvRTF := TRvRenderRTF.Create(Self);
FRvRTF.DisplayName := 'RTF格式(RTF)';
FRvText := TRvRenderText.Create(Self);
FRvText.DisplayName := '文本文件(TXT)';
end;

destructor TDataSet2RaveRpt.Destroy;
begin
FDSRpt.GotoBookmark(FOldBkMark);
FDSRpt.FreeBookmark(FOldBkMark);
FRvPDF.Free;
FRvHTML.Free;
FRvRTF.Free;
FRvText.Free;
FRvsys.Free;
inherited;
end;

procedure TDataSet2RaveRpt.SetMarginLeft(Value:do
uble);
begin
if Assigned(FRvSys) then
FRvSys.SystemPrinter.MarginLeft := Value;
end;

procedure TDataSet2RaveRpt.SetMarginTop(Value:do
uble);
begin
if Assigned(FRvSys) then
FRvSys.SystemPrinter.MarginTop := Value;
end;

procedure TDataSet2RaveRpt.SetMarginRight(Value:do
uble);
begin
if Assigned(FRvSys) then
FRvSys.SystemPrinter.MarginRight := Value;
end;

procedure TDataSet2RaveRpt.SetMarginBottom(Value:do
uble);
begin
if Assigned(FRvSys) then
FRvSys.SystemPrinter.MarginBottom := Value;
end;

procedure TDataSet2RaveRpt.SetOrientation(Value: TOrientation);
begin
if Assigned(FRvSys) then
FRvSys.SystemPrinter.Orientation := Value;
end;

procedure TDataSet2RaveRpt.SetTitle(Value: WideString);
begin
if Assigned(FRvSys) then
begin
FRvSys.SystemPrinter.Title := Value;
FRvSys.TitlePreview := Value;
end;
end;

//初始化操作
procedure TDataSet2RaveRpt.Init;
const
ColTypes = [ftString, ftSmallint, ftInteger, ftWord, ftBoolean, ftFloat,
ftCurrency, ftBCD, ftDate, ftTime, ftDateTime, ftBytes,
ftVarBytes, ftAutoInc, ftFixedChar, ftWideString, ftLargeint,
ftGuid, ftTimeStamp, ftFMTBcd];
var
i, ColNum: Integer;
dWidth:do
uble;
begin
FOldBkMark := FDSRpt.GetBookmark;
//保存数据集的原始游标
ColNum := 0;
for i:=0 to FDSRpt.Fields.Count-1do
if (FDSRpt.Fields.Visible) and
(FDSRpt.Fields.DataType in ColTypes) then
begin
Inc(ColNum);
SetLength(FCols, ColNum);
SetLength(FWidths, ColNum);
//注意:FCols数组下标是从0开始
FCols[ColNum - 1] := i;
//根据BaseReport的相关属性来设置宽度
dWidth := Length(FDSRpt.Fields.DisplayLabel);
if dWidth<=5 then
// 修改宽度设置方法
dWidth := 0.5
else
if dWidth<=10 then
dWidth := 0.75
else
if dWidth<=30 then
dWidth := 1.25
else
dWidth := 1.75;
FWidths[ColNum - 1] := dWidth;

end;
end;

//打印数据列标题
procedure TDataSet2RaveRpt.PrintColHeader(Report: TBaseReport);
var
i: Integer;
dPos, dMargin:do
uble;
bShade: Byte;
begin
with Reportdo
begin
SectionTop := 0.5;
SectionBottom := 11.75;
// SectionLeft := 0.5;
// SectionRight := 0.5;
Home;
YPos := 0.5;
ClearTabs;
SetPen(clBlack, psSolid, 1, pmCopy);
FontSize := 10;

Bold := True;
dMargin := 0;
bShade := 10;
//制表并输出列标题
for i:=0 to High(FCols)do
begin
if i=0 then
//第一列
begin
dPos := 0.5;
SetTab(dPos, pjCenter, FWidths, dMargin, BOXLINEALL, bShade);
Tab(-2, NA, -2, -2, NA);
if High(FCols)=0 then
//若是最后一列
Println(FDSRpt.Fields[FCols].DisplayLabel)
else
Print(FDSRpt.Fields[FCols].DisplayLabel);
end
else
if (i>0) and (i<High(FCols)) then
//中间的各列
begin
dPos := NA;
SetTab(dPos, pjCenter, FWidths, dMargin, BOXLINEALL, bShade);
Tab(NA, NA, -2, -2, NA);
Print(FDSRpt.Fields[FCols].DisplayLabel);
end
else
//最后一列
begin
dPos := NA;
SetTab(dPos, pjCenter, FWidths, dMargin, BOXLINEALL, bShade);
Tab(NA, -2, -2, -2, NA);
Println(FDSRpt.Fields[FCols].DisplayLabel);
end;
end;
Bold := False;
end;
end;

//打印数据行
procedure TDataSet2RaveRpt.PrintData(Report: TBaseReport);
var
Content: String;
i: Integer;
dPos, dMargin:do
uble;
bShade: Byte;
begin
with Reportdo
begin
ClearTabs;
// SetTopOfPage;
//Home;
FontSize := 10;
dMargin := 1;
bShade := 0;
//制表
for i:=0 to High(FCols)do
begin
if i=0 then
dPos := 0.5
else
dPos := NA;
SetTab(dPos, pjLeft, FWidths, dMargin, BOXLINEALL, bShade);
end;
//输出数据行
FDSRpt.First;
while not FDSRpt.Eofdo
begin
// 字符太多一格不够显示时如何自动换行
Content := '';
for i:=0 to High(FCols)do
Content := Content + #9 + FDSRpt.Fields[FCols].AsString;
Println(Content);
FDSRpt.Next;
end;
end;
end;

//打印DataSet数据
procedure TDataSet2RaveRpt.MyOnPrint(Sender: TObject);
var
Report: TBaseReport;
begin
Report := Sender as TBaseReport;
// TBaseReport坐标的具体含意及设置
PrintData(Report);
end;

//打印一个新页
procedure TDataSet2RaveRpt.MyOnNewPage(Sender: TObject);

begin
with (Sender as TBaseReport)do
begin
FontName := '宋体';
FontCharset := GB2312_CHARSET;
FontSize := 8;
SectionTop := 0.1;
PrintHeader('test', pjLeft);
SectionBottom := 11.5;
// SectionLeft := 0.25;
// SectionRight := 0.25;
PrintFooter('第' + macro(midCurrentPage) + '页(共' + macro(midTotalPages) +
'页)', pjLeft);
PrintFooter('时间:' + macro(midCurrTimeShort), pjRight);
PrintColHeader(Sender as TBaseReport);
end;
end;

procedure TDataSet2RaveRpt.Print;
begin
if Assigned(FRvSys) then
try
if not FDSRpt.Active then
FDSRpt.Active := True;
//不要使用Open方法
Init;
FRvSys.Execute;
except
FDSRpt.Close;
end;
end;
end.
 
请问RAVE有无DEMO和教程啊,谢谢
 
找到了给我一份,谢谢!lsssxs@360c.ncom
 
在www.51delphi.com有篇rave初识
 
到www.nevrona.com下载rave5的demo和pdf格式的学习资料
我已经下载了
 
看的不错
 

Similar threads

D
回复
0
查看
930
DelphiTeacher的专栏
D
D
回复
0
查看
871
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部