📄 frame_printutils.pas
字号:
unit frame_PrintUtils;
interface
uses
classes, Forms, sysUtils, easyGrid, DB, types,frame_UtilFunc;
procedure PrintInfo(ReportName:string;PrintInfo:TstringList);
procedure PrintTable(ReportName:string;aDataSet:TDataSet;PrintInfo:TstringList;FixLine:integer=0);overload;
procedure PrintTable(ReportName:string;aDataSet:TDataSet);overload;
implementation
procedure PrintInfo(ReportName:string;PrintInfo:TstringList);
var
eg: TEasyGrid;
i,j:integer;
begin
eg := TEasyGrid.Create(nil);
eg.Parent:= Application.MainForm;
eg.Visible:= False;
if Not FileExists(ExtractFilePath(Application.ExeName)+ 'Dat\'+ ReportName+ '.eg') then
begin
ErrorDlg('错误:打印格式文件' + ReportName + '.eg 不存在!');
WriteLog('错误:打印格式文件' + ReportName + '.eg 不存在!');
eg.Free;
exit;
end;
eg.LoadFromFile(ExtractFilePath(Application.ExeName)+ 'Dat\' + ReportName+ '.eg');
if FileExists(ExtractFilePath(Application.ExeName)+ 'Dat\'+ ReportName+ '.pi') then
begin
eg.EasyGridPageInfo.LoadFromFile(ExtractFilePath(Application.ExeName)+ 'Dat\' + ReportName+ '.pi');
end;
for i:=0 to eg.ColCount-1 do
for j:=0 to eg.RowCount-1 do
begin
if eg.Cells[i,j].BackText <> '' then
begin
eg.Cells[i,j].ForeText := PrintInfo.Values[eg.Cells[i,j].BackText]
end;
end;
eg.AdJustRowHeight;
eg.EasyGridPageInfo.DetailPageInfo.PrintGridLine:= false;
eg.Preview;
eg.Free;
end;
procedure PrintTable(ReportName:string;aDataSet:TDataSet;PrintInfo:TstringList;FixLine:integer=0);
var
eg: TEasyGrid;
i,j,k:integer;
CurRow,BeginRow,EndRow,RecRowCount:integer;
FillRec:boolean;
tmpRect:TRect;
begin
eg := TEasyGrid.Create(nil);
eg.Parent:= Application.MainForm;
eg.Visible:= False;
if Not FileExists(ExtractFilePath(Application.ExeName)+ 'Dat\'+ ReportName+ '.eg') then
begin
ErrorDlg('错误:打印格式文件' + ReportName + '.eg 不存在!');
WriteLog('错误:打印格式文件' + ReportName + '.eg 不存在!');
eg.Free;
exit;
end;
eg.LoadFromFile(ExtractFilePath(Application.ExeName)+ 'Dat\' + ReportName+ '.eg');
if FileExists(ExtractFilePath(Application.ExeName)+ 'Dat\'+ ReportName+ '.pi') then
begin
eg.EasyGridPageInfo.LoadFromFile(ExtractFilePath(Application.ExeName)+ 'Dat\' + ReportName+ '.pi');
end;
if FixLine<>0 then eg.FixedRows := FixLine;
for i:=0 to eg.ColCount-1 do
for j:=0 to eg.RowCount-1 do
begin
if eg.Cells[i,j].BackText <> '' then
begin
eg.Cells[i,j].ForeText := PrintInfo.Values[eg.Cells[i,j].BackText]
end;
end;
With aDataSet do
begin
if Active then
begin
// 决定单条纪录的行数
RecRowCount:=1;
BeginRow := 9999;
endRow :=1;
for i:=0 to eg.ColCount-1 do
for j:=0 to eg.RowCount-1 do
begin
if eg.Cells[i,j].BackText <> '' then
begin
for k:=0 to FieldCount-1 do
begin
if (UpperCase(eg.Cells[i,j].BackText) = UpperCase(Fields[k].FieldName))
or (UpperCase(eg.Cells[i,j].BackText) = UpperCase('记录空行'))then
begin
if j< BeginRow then beginrow:=j;
if j>EndRow then EndRow:=j;
end;
end;
end;
end;
if BeginRow=9999 then
begin
FillRec:=False;
beginrow:=1;
end
else
begin
FillRec:=True;
end;
RecRowCount:=EndRow-BeginRow+1;
tmpRect.Left := 1;
tmpRect.Right := eg.ColCount -1;
tmpRect.Top := BeginRow;
tmpRect.Bottom := EndRow;
CurRow := BeginRow;
if FillRec then
begin
First;
While Not aDataSet.Eof do
begin
eg.CopyCells(tmpRect);
eg.InsertRow(tmpRect);
eg.PasteCells(tmprect.TopLeft);
for i:=0 to eg.colCount-1 do
for j:=CurRow to CurRow+RecRowCount-1 do
begin
if eg.Cells[i,j].BackText <> '' then
begin
for k:=0 to FieldCount-1 do
begin
if UpperCase(eg.Cells[i,j].BackText) = UpperCase(Fields[k].FieldName) then
begin
eg.Cells[i,j].ForeText := Fields[k].AsString;
end; // end backtext=fieldname
end; // end for fieldcount
end; // end for recrowcount
end; //end for colcount
tmpRect.Top:=tmpRect.Top + RecRowCount;
tmpRect.Bottom := tmprect.Top + RecRowCount-1;
Currow := CurRow + RecRowCount;
Next;
end; // end while next
eg.DeleteRow(tmpRect);
end; // end if fillrec
end; // end if active
end; // end with
eg.AdJustRowHeight;
eg.EasyGridPageInfo.DetailPageInfo.PrintGridLine:= false;
eg.Preview;
eg.Free;
end;
procedure PrintTable(ReportName:string;aDataSet:TDataSet);overload;
var
PrintInfo :TstringList;
begin
PrintInfo := TstringList.Create;
PrintTable(ReportName,aDataSet,PrintInfo);
PrintInfo.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -