报表高手请进~~~~~~~~~~~急急急急急!!!!!!!!!!!!分数不够可以加 (200分)

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

jerryjean

Unregistered / Unconfirmed
GUEST, unregistred user!
能不能不在reportMachine设计器中预览和打印,自己添加两个按钮,一个是预览,一个是打印。
注意:
在我进行预览和打印的时候才把先前已经定义好的.rmf格式装载进来(先前只是定义了格式,
而没有相关数据的绑定);
并且此时才把数据和已装载的格式相绑定。
最后预览和打印。
 
用reportMachine可以实现。
请到这个网站来看。
http://www.jnnj110.gov.cn/jingning
 
如果你想要简单,就对应ABC做三个不同的报表,选A,B,C时对应不同的报表就是了!
复杂的话就根据你的数据源来生成报表!如果你是用QUICKREPORT的话,我有一个例子!
 
to hpretty:
我现在的报表是动态生成的不仅仅只是abc这三个,要允许用户动态的添加格式,quickreport的
没有办法让用户在运行状态下设计报表格式的吧。
 
不知道你打印的是不是DBGRID,如果是根据DBGRID来指定格式的话其实可以用Ehx那一套控件来实现
 
可以的呀!谁说不可以,我剁死他!看看我的代码吧!
unit GeneralReport;
interface
uses Windows, SysUtils, Messages, Classes, Graphics, Controls,
StdCtrls, ExtCtrls, Forms, Quickrpt, QRCtrls, Db, DBTables, Dialogs, Printers;
type
TReport = class(TQuickRep)
GroupHeader: TQRGroup;
Detail: TQRBand;
Footer: TQRBand;
Summary: TQRBand;
Data: TQuery;
PageHeader: TQRBand;
procedure DataAfterOpen(DataSet: TDataSet);
private
Fwidth: array of Integer;
StartColumn: Integer;
FLeft: array of Integer;
GroupField: string;
GTop, PerWidth: Integer;
FwidthList: string;
procedure GetWidth(widthList: string);
// 根据指定的宽度来设定列宽!
procedure GetLeftAndWidth;
// 得到列左边和列宽的数据
procedure SetColumnTitle;
// 设定列标题
procedure SetColumn;
// 设定列对应的字段
procedure SetFooter;
procedure AddTitle;
// 设定小组统计的字段名
procedure SetSummary;
// 统计求和值
procedure AddHeadText;
//增加分组题头
procedure AddTotalText;
//添加统计字头
procedure AddPageCountAndDate;
// 添加页码和打印日期
public
procedure GeneralReport_custom(sourceSQL, Title, pGroupField, WidthList:
string;
FirstColumn, HeadText, TotalText, PageCount, GroupNewPage, pfoot,
psummary: Boolean;
pwidth,
plength: Integer;
pTop, pperWidth, headerHeigth, detailHeigth: Integer);
procedure DeleteAllControl;
end;

var
Report: TReport;
procedure GetFeeStatics(SQL, title, pGroupField: string);
const
LeftM = 10;
const
Line = 5;
const
ColumnName = 'LColumName';
const
ExprDetail = 'ExprDetail';
const
ExprFooter = 'ExprFooter';
const
ExprSummary = 'ExprSummary';
const
QRDetail = 'QRDetail';
const
QRFooter = 'QRFooter';
const
QRGroup = 'QRGroup';
const
QRSummary = 'QRSummary';
procedure SetPageWidthLength(Width, Length: Integer);
// sourceSQL :sourceSQL of the report content ;
title :The title of the report
// pGroupField :the field Which the report Grouped by ;
WidthList :String of the width of each column
// firstColumn : print first Column ? ;
Headtext .....
// pWidth ,pLength : width and length of the page ;
ptop :the heigth of the top margin
// pperWidth :the comon width of columns ;
headerHeigth,detailHeigth : the heigth of detail and header Bands
// 通用报表过程
implementation
{$R *.DFM}
uses databaseSet;
procedure TReport.SetColumn;
var
i: Integer;
begin
if not data.Active then
Exit;
with detail.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRdetail + '00';
Shape := qrsRectangle;
Left := Fleft[0];
Top := 0;
Width := FLeft[Data.fieldcount] - fleft[0];
Height := Detail.Height;
end;
for i := startColumn to Data.FieldCount - 1do
begin
if (Data.Fields.DataType in
[ftCurrency, ftSmallint, ftInteger, ftWord, ftFloat]) then
with detail.AddPrintable(TQRExpr) as TQRExprdo
begin
Name := ExprDetail + IntToStr(i);
AutoSize := False;
Top := line;
Width := FWidth - 4;
Left := Fleft[i + 1] - Width - 5;
AlignMent := taRightJustify;
Expression := 'DATA.' + Data.Fields.FieldName;
Mask := '###,##0.00';
end
else
with detail.AddPrintable(TQRExpr) as TQRExprdo
begin
Name := ExprDetail + IntToStr(i);
AutoSize := True;
Top := line;
Left := Fleft + 8;
AlignMent := taLeftJustify;
Expression := 'DATA.' + Data.Fields.FieldName;
end;
if i > startColumn then
with Detail.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRDetail + IntToStr(i);
Shape := qrsVertLine;
Left := Fleft - 30;
Top := 0;
Height := Detail.Height;
end;
end;
end;

procedure TReport.SetColumnTitle;
var
i: Integer;
begin
if not data.Active then
Exit;
with PageHeader.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRGroup + '00';
Shape := qrsRectangle;
Left := Fleft[0];
Top := GTop;
Width := FLeft[Data.fieldcount] - fleft[0];
Height := PageHeader.Height - Gtop;
end;
for i := startColumn to Data.FieldCount - 1do
begin
with PageHeader.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := ColumnName + IntToStr(i);
Caption := Data.Fields.FieldName;
AutoSize := True;
Left := (Fleft + Fleft[i + 1]) div 2 - 3 * Length(Caption);
Top := GTop + line;
AlignMent := taleftJustify;
Caption := Data.Fields.FieldName;
end;
if i > startColumn then
with PageHeader.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRGroup + IntToStr(i);
Shape := qrsVertLine;
Left := Fleft - 30;
Top := GTop;
end;
end;
end;

procedure TReport.SetFooter;
var
i: Integer;
begin
if not data.Active then
Exit;
with Footer.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRFooter + '00';
Shape := qrsRectangle;
Left := Fleft[0];
Top := 0;
Width := FLeft[Data.fieldcount] - fleft[0];
Height := Footer.Height;
end;
for i := startColumn to Data.FieldCount - 1do
begin
if i > startColumn then
if (Data.Fields.DataType in
[ftCurrency, ftSmallint, ftInteger, ftWord, ftFloat]) then
with Footer.AddPrintable(TQRExpr) as TQRExprdo
begin
Name := ExprFooter + IntToStr(i);
AutoSize := False;
Width := FWidth - 7;
Left := Fleft + Line;
Top := line;
Left := Fleft[i + 1] - Width - 5;
AlignMent := taRightJustify;
ResetAfterPrint := True;
Expression := 'sum(Data.' + Data.Fields.FieldName + ')';
Mask := '###,##0.00';
if Pos('读数', Data.Fields.FieldName) > 0 then
begin
Expression := '';
Mask := '###,##0.0'
end;
end;
if i > startColumn then
with Footer.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRfooter + IntToStr(i);
Shape := qrsVertLine;
Left := Fleft - 30;
Top := 0;
Height := Footer.Height;
end;
end;
end;

procedure TReport.SetSummary;
var
i: Integer;
begin
if not data.Active then
Exit;
with summary.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRSummary + '00';
Shape := qrsRectangle;
Left := Fleft[0];
Top := 0;
Width := FLeft[Data.fieldcount] - fleft[0];
Height := summary.Height;
end;
for i := startColumn to Data.FieldCount - 1do
begin
if i > startColumn then
with summary.AddPrintable(TQRShape) as TQRShapedo
begin
Name := QRsummary + IntToStr(i);
Shape := qrsVertLine;
Left := Fleft - 30;
Top := 0;
Height := summary.Height;
end;
if i > startColumn then
if (Data.Fields.DataType in
[ftCurrency, ftSmallint, ftInteger, ftWord, ftFloat]) then
with summary.AddPrintable(TQRExpr) as TQRExprdo
begin
Name := ExprSummary + IntToStr(i);
AutoSize := False;
Width := FWidth - 9;
Left := Fleft + Line;
Top := line;
Left := Fleft[i + 1] - Width -5;
AlignMent := taRightJustify;
Expression := 'Sum(Data.' + Data.Fields.FieldName + ')';
Mask := '###,##0.00';
if Pos('读数', Data.Fields.FieldName) > 0 then
begin
Expression := '';
Mask := '###,##0.0'
end;
end;
end;
end;

procedure TReport.GetLeftAndWidth;
var
i: Integer;
begin
if not Data.Active then
Exit;
setLength(FLeft, Data.FieldCount + 1);
SetLength(FWidth, Data.FieldCount + 1);
if FWidthList <> '' then
GetWidth(FWidthList);
FLeft[0] := LeftM;
for i := 0 to Data.FieldCount - 1do
begin
if FWidth = 0 then
FWidth := PerWidth;
end;
if StartColumn = 1 then
FLeft[1] := LeftM;
for i := startcolumn + 1 to Data.FieldCountdo
begin
FLeft := FLeft[i - 1] + FWidth[i - 1];
end;
end;

procedure TReport.DataAfterOpen(DataSet: TDataSet);
begin
GetLeftAndWidth;
SetColumntitle;
SetColumn;
SetFooter;
SetSummary;
//AddTotalText;
end;

procedure Report_PaidCustom(sourceSQL, Title: string;
FirstColumn: Boolean);
begin
end;

procedure TReport.AddHeadText;
begin
with PageHeader.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'HeadText';
AutoSize := False;
Caption := GroupField + ':';
Left := 20;
Width :=PageHeader.Width;
Top := GTop - 25;
end;
with PageHeader.AddPrintable(TQRExpr) as TQRExprdo
begin
//pt := PageHeader.FindComponent('HeadText') as TQRLabel;
Name := 'HeadField';
Expression := 'Data.' + GroupField;
Left := FLeft[2];
Top := GTop - 25;
end;
end;

procedure TReport.AddTotalText;
begin
with Summary.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'SummaryText';
Caption := '总计:';
Left := Fleft[2] -35;
Top := line;
end;
with Footer.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'FooterText';
Caption := '小计:';
Left := Fleft[2] -35;
Top := Line;
end;
end;

procedure Report_FeeList(sourceSQL, Title: string;
firstColumn: Boolean);
begin

end;

procedure TReport.AddPageCountAndDate;
var
textLeftpos: Integer;
begin
textLeftpos := Report.Width - 300;
with PageHeader.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'printDate';
Caption := '打印日期:';
Left := textLeftpos - 50;
Top := Gtop - 25;
end;
with PageHeader.AddPrintable(TQRSysData) as TQRSysDatado
begin
Name := 'QRSysDataPrintDate';
Data := qrsDate;
Left := textLeftpos + 10;
Top := Gtop - 25;
end;
with PageHeader.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'PageText1';
Caption := '第';
Left := textLeftpos + 75;
Top := Gtop - 25;
end;
with PageHeader.AddPrintable(TQRSysData) as TQRSysDatado
begin
Name := 'QRsysdataPage';
Data := qrsPageNumber;
Left := textLeftpos + 90;
Top := Gtop - 25;
end;
with PageHeader.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'PageText2';
Caption := '页';
Left := textLeftpos + 110;
Top := Gtop - 25;
end;
end;

procedure TReport.GeneralReport_custom(sourceSQL, Title, pGroupField, WidthList:
string;
FirstColumn, HeadText, TotalText, PageCount, GroupNewPage, pfoot, psummary:
Boolean;
pwidth,
plength: Integer;
pTop, pperWidth, headerHeigth, detailHeigth: Integer);
var
pt: TQRLabel;
begin
with reportdo
begin
try
SetPageWidthLength(pwidth, plength);
except
Application.MessageBox('设置打印机纸张不成功!', '提示信息', 0);
end;
AddTitle;
GroupHeader.ForceNewPage := GroupNewPage;
ReportTitle := Title;
page.Width := pWidth;
Page.Length := PLength;
GTop := pTop;
PageHeader.Height := HeaderHeigth;
perWidth := pperWidth;
detail.Height := detailHeigth;
GRoupField := pGroupField;
Footer.Enabled := pfoot;
summary.Enabled := psummary;
GroupHeader.Expression := 'Data.' + GroupField;
if GroupField = '' then
Footer.Enabled := False;
FWidthList := WidthList;
if FirstColumn then
StartColumn := 0
else
StartColumn := 1;
Data.sql.Text := SourceSQL;
Data.DatabaseName := Globalinfos.DatabaseName;
try
data.Open;
if (GRoupField <> '') and (HeadText) then
AddHeadText;
if TotalText then
AddTotalText;
if PageCount then
AddPageCountAndDate;
pt := Findcomponent('LTitle') as TQRLabel;
pt.Caption := Title;
try
finally
end;
finally
//free;
end;
end;
end;

procedure TReport.GetWidth(widthList: string);
var
str: string;
FEverywidth, i: Integer;
begin
str := WidthList;
i := 0;
while not (trim(str) = '')do
begin
Feverywidth := StrtoInt(trim(Copy(str, 1, Pos('/', str) - 1)));
Fwidth := FEveryWidth;
str := trim(Copy(str, Pos('/', str) + 1, Length(str) - Pos('/', str)));
i := i + 1;
end;
end;

procedure SetPageWidthLength(Width, Length: Integer);
var
aDevice: array[0..CCHDEVICENAME - 1] of char;
aDriver: array[0..MAX_PATH - 1] of char;
aPort: array[0..31] of char;
hDevMode: THandle;
pDevMode: PDeviceMode;
printer: Tprinter;
begin
// 获取打印机DeviceMode的句柄
printer := Tprinter.Create();
Printer.GetPrinter(aDevice, aDriver, aPort, hDevMode);
if hDevMode <> 0 then
begin
// 获取指向DeviceMode的指针
pDevMode := GlobalLock(hDevMode);
if pDevMode <> nil then
begin
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERLENGTH;
pDevMode^.dmPaperWidth := Length;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERWIDTH;
pDevMode^.dmPaperLength := Width;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERSIZE;
pDevMode^.dmPaperSize := DMPAPER_USER;
ResetDC(Printer.Handle, pDevMode^);
GlobalUnlock(hDevMode);
end;
end;
printer.Free;
end;

procedure TReport.AddTitle;
begin
with PageHeader.AddPrintable(TQRLabel) as TQRLabeldo
begin
Name := 'LTitle';
Font.Name := '宋体';
Font.Size := 14;
AutoSize := False;
Left := 0;
AlignMent := taCenter;
Width :=PageHeader.Width;
Top := GTop - 5;
end;
end;

procedure GetFeeStatics(SQL, title, pGroupField: string);
var
pt: TQRLabel;
begin
Report := TReport.Create(nil);
with reportdo
begin
AddTitle;
GroupHeader.ForceNewPage := True;
ReportTitle := Title;
GTop := 60;
PageHeader.Height := 85;
perWidth := 88;
detail.Height := 25;
GRoupField := pGroupField;
GroupHeader.Expression := 'Data.' + GroupField;
Footer.Enabled := False;
Summary.Enabled := False;
StartColumn := 1;
Data.sql.Text := SQL;
Data.DatabaseName := Globalinfos.DatabaseName;
try
data.Open;
AddPageCountAndDate;
AddHeadText;
pt := Findcomponent('LTitle') as TQRLabel;
pt.Caption := Title;
pt.Left := Footer.Width div 2 - Length(pt.Caption) * 7;
pt := nil;
pt.Free;
try
Preview;
except
end;
finally
Free;
//DeleteAllControls;
end;

end;

end;

procedure TReport.DeleteAllControl;
var
i:integer;
begin
for i := 0 to PageHeader.ComponentCount -1do
begin
with PageHeaderdo
begin
Components.Free;
end;
end;
for i := 0 to Detail.ComponentCount -1do
begin
with Detaildo
begin
Components.Free;
end;
end;
for i := 0 to Footer.ComponentCount -1do
begin
with Footerdo
begin
Components.Free;
end;
end;
for i := 0 to Summary.ComponentCount -1do
begin
with Summarydo
begin
Components.Free;
end;
end;

end;

end.

 
to hpretty高手:
谢谢你的指教~~~~~~~~~~~不过我现在没有时间来看代码。
且reportMachine已经解决了我很多问题,要我回头再走,有些不合算。
不知道你能否以reportMachine或者fastReport控件给我点建议。谢谢~~~~~~
 
reportMachine应该到reportMachine的用户论坛www.pcjingning.com上问,因为是有源码的,所以你问一下作者如何改就行了。
我想是可以的。
 
很公平吧
 
多人接受答案了。
 
后退
顶部