关于F1Book的打印问题(200分)

  • 主题发起人 主题发起人 siyan
  • 开始时间 开始时间
S

siyan

Unregistered / Unconfirmed
GUEST, unregistred user!
我在一台连接600*600dpi打印机的机器上设置好我的F1Book表格
然后在到一台连接360*360dpi打印机的机器上对表格进行打印,发现
表格被缩小了,我根据分辨率的比例,在程序中自动调节F1Book的行高
和列宽(将原值*600/360),所得的表格预览时却远远大于连接600*600dpi
打印机时的效果,请指教[:(!]
 
有个专门的打印预览控件,不知道有没有用.
 
就没有答案了吗?
sigh!
 
{*****************************************}
{ }
{ Report Machine v2.0 }
{ F1Book6 Report v1.07 }
{ Arm Tech Group }
{ 425007@sina.com }
{*****************************************}
unit RM_F1book6;
interface
{$I RM.INC}
{$IFDEF F1book6}
{2002-3-1 修正了合并单元的对齐问题}
{2002-3-5 修正了显示问题}
uses
SysUtils,Windows,Dialogs,Classes,Graphics,Controls,TTF160_TLB,RM_DSet,RM_Class,
RM_FormReport;
Const
Ver=1.07;

type
TRMPrintF1Book = class(TComponent) // fake component

end;


{ TRMPrintF1book6 }
TRMPrintF1book6 = class(TRMFormReportObject)
private
BookHeight:integer;
Bookwidth:integer;
BookHeight1:integer;
BookWidth1:integer;

FFormReport: TRMFormReport;
FGrid: TF1Book6;
FUserDataset: TRMUserDataset;
FList: TStringList;
FCurrentRow: Integer;
procedure OnUserDatasetCheckEOF(Sender: TObject;
var Eof: Boolean);
procedure OnUserDatasetFirst(Sender: TObject);
procedure OnUserDatasetNext(Sender: TObject);
procedure OnUserDatasetPrior(Sender: TObject);
procedure OnReportbegin
Band(Band: TRMBand);
procedure SetMemos;
public
constructor CreateObject;
override;
destructor Destroy;
override;
procedure OnGenerate_Object(aFormReport: TRMFormReport;
Page: TRMPage;
Control: TControl;
var t: TRMView);
override;
end;

Function IsNumber(S:String):boolean;
{$ENDIF}
implementation

{$IFDEF F1book6}
uses RM_Utils;


type
THackBook=Class(TF1book6)
end;


THackFormReport = class(TRMFormReport)
end;


{ TRMPrintF1book6 }

constructor TRMPrintF1book6.CreateObject;
var
i:integer;
begin

inherited CreateObject;
AutoFree := False;

end;


destructor TRMPrintF1book6.Destroy;
begin

if FUserDataset <> nil then

begin

FUserDataset.Free;
FUserDataset := nil;
end;

if FList <> nil then

begin

FList.Free;
FList := nil;
end;

inherited Destroy;
end;


procedure TRMPrintF1book6.OnGenerate_Object(aFormReport: TRMFormReport;
Page: TRMPage;
Control: TControl;
var t: TRMView);
var
liView: TRMMemoView;
i,j, liPageNo, Leftx, NextLeft, NextTop: Integer;
liNum: Integer;
liGrid: THackBook;
s: string;
liPage: TRMPage;
liGridTitleHeight: Integer;
//初始单元格大小设置
procedure GetCellWidthHeight;
var
i:integer;
begin

BookHeight:=18;
Bookwidth:=75;
BookHeight1:=210;
BookWidth1:=961;
for i:=1 to FGrid.LastRowdo

if Bookheight1>FGrid.RowHeight then

BookHeight1:=FGrid.RowHeight;

for i:=1 to FGrid.LastColdo

if BookWidth1>FGrid.ColwidthTwips then

BookWidth1:=FGrid.ColwidthTwips;

end;

procedure MakeOneHeader(aRow, aIndex: Integer);
Procedure FormatOneHeader(RowNo,ColNo:integer);
var
j:integer;
liHeight,temp,pRow1,pCol1,pRow2, pCol2:integer;
Cellformat:F1CellFormat;
begin

liHeight := (THackBook(FGrid).RowHeight[RowNo] div Bookheight1) *BookHeight+4 ;

if (ColNo div 26)=0 then

FGrid.Selection:=Chr(64+ColNo)+inttostr(RowNo)
else

FGrid.Selection:=Chr(64+(ColNo div 26))+Chr(64+(ColNo mod 26))+inttostr(FCurrentRow);
begin

FGrid.GetSelection(0,pRow1,pCol1,pRow2, pCol2);
If (pRow1<pRow2) and (pRow1=RowNo) then

begin

Temp:=0 ;
For J:=pRow1 to pRow2do

Temp:=Temp+(THackBook(FGrid).RowHeight[J] div Bookheight1) *BookHeight+4;
liView.dy:=temp;
end
else

liView.dy:=liHeight;
If (pCol1<pCol2) and (pCol1=ColNo) then

begin

Temp:=0 ;
For J:=pCol1 to pCol2do

Temp:=Temp+(THackBook(FGrid).ColWidthtwips[J] div BookWidth1)*BookWidth+1;
liView.dx:=Temp;
end
else

liView.dx:=(THackBook(FGrid).ColWidthtwips[ColNo] div BookWidth1)*BookWidth+1;
end;

//对齐方式
FGrid.SetActiveCell(RowNo,ColNo);
s:=FGrid.TextRC[RowNo,ColNo];
Cellformat:=FGrid.GetCellFormat;
//水平排列
If CellFormat.AlignHorizontal=F1HAlignCenter then

LiView.pAlignment:=rmtaCenterJustify;
If CellFormat.AlignHorizontal=F1HalignRight then

LiView.pAlignment:=rmtaRightJustify;
If CellFormat.AlignHorizontal=F1HAlignLeft then

LiView.pAlignment:=rmtaLeftJustify;
{//垂直排列}
If CellFormat.AlignVertical=F1VAlignTop then

LiView.pLayout:=rmtlTop;
If CellFormat.AlignVertical=F1VAlignCenter then

LiView.pLayout:=rmtlCenter;
If CellFormat.AlignVertical=F1VAlignBottom then

LiView.pLayout:=rmtlBottom;
//
if CellFormat.AlignHorizontal=F1HAlignGeneral then

if IsNumber(s) then

LiView.pAlignment:=rmtaRightJustify
else

LiView.pAlignment:=rmtaLeftJustify;
//字体
LiView.Font.Name:=CellFormat.FontName;
LiView.Font.Size:=CellFormat.FontSize;
LiView.Font.Color:=CellFormat.FontColor;
Liview.Font.Style:=[];
if CellFormat.FontBold then

Liview.Font.Style:=LiView.Font.style+[fsBold];
if CellFormat.FontItalic then

Liview.Font.Style:=LiView.Font.style+[fsItalic];
if CellFormat.FontUnderline then

Liview.Font.Style:=LiView.Font.style+[fsUnderline];
if CellFormat.FontStrikeout then

Liview.Font.Style:=LiView.Font.style+[fsStrikeOut];
//画表格线
FGrid.GetSelection(0,pRow1,pCol1,pRow2, pCol2);
Liview.prop['FrameTyp']:=RMftNone;
{DONE -oArm:在固定列,固定行>0换页时,固定行的合并单元格的右边边界未画}
{解决办法: 1 加一个参数判断是否是换页
2 不加理会(实际应用中行和列同时固定的可能性较少)}
IF RowNo=PRow1 then

If cellformat.BorderStyle[F1TopBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftTop;
IF ColNo=PCol1 then

If cellformat.BorderStyle[F1LeftBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftLeft;
IF RowNo=PRow2 then

If cellformat.BorderStyle[F1BottomBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftBottom;
IF ColNo=PCol2 then

If cellformat.BorderStyle[F1RightBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftRight;
end;


begin

liView := TRMMemoView(RMCreateObject(gtMemo,''));
liView.CreateUniqueName;
// liView.PLayout := rmtlCenter;
// liView.PAlignment := rmtaCenterJustify;
liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
liView.PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
liView.x := NextLeft;
liView.y := NextTop;
{DONE -oArm:表头的字体问题}
FormatOneHeader(aRow,aIndex);
liView.Memo.Text :=liGrid.TextRC[ aRow,aIndex];
liPage.Objects.Add(liView);
aFormReport.PageHeaderViews.Add(liView);
NextLeft:=NextLeft+liGrid.ColWidthTwips[aIndex] div BookWidth1 * BookWidth + 1;
end;



procedure MakeOneDetail(aIndex: Integer);
var
i:integer;
begin

if NextLeft=0 then

begin

for i:=1 to aFormReport.GridFixedColsdo

begin

liView := TRMMemoView(RMCreateObject(gtMemo, ''));
liView.CreateUniqueName;
liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
liView.PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
liView.x := NextLeft;
liView.dx :=liGrid.ColWidthTwips div BookWidth1 * BookWidth + 1;
liView.y :=0;
liView.dy :=BookHeight;
liView.Font.Assign(liGrid.Font);
liPage.Objects.Add(liView);
aFormReport.PageDetailViews.Add(liView);
FList.Add(liView.Name+'$'+IntToStr(I));
NextLeft := NextLeft + liView.dx;
end;

end;

if aIndex<=aFormReport.GridFixedCols then
//
exit;
liView := TRMMemoView(RMCreateObject(gtMemo, ''));
liView.CreateUniqueName;
liView.PStretched := rmgoStretch in aFormReport.ReportOptions;
liView.PWordWrap := rmgoWordWrap in aFormReport.ReportOptions;
liView.x := NextLeft;
liView.dx :=liGrid.ColWidthTwips[aIndex] div BookWidth1 * BookWidth + 1;
liView.y :=0;
liView.dy :=BookHeight;
liPage.Objects.Add(liView);
aFormReport.PageDetailViews.Add(liView);
FList.Add(liView.Name);
NextLeft := NextLeft + liView.dx;
end;

procedure DrawFixedHeader(aRow: Integer);
var
j: Integer;
begin

for j := 1 to aFormReport.GridFixedCols do

begin

if j < liGrid.LastCol then

MakeOneHeader(aRow, j);
end;

end;

begin

if aFormReport.DrawOnPageFooter then
exit;
liGrid := THackBook(Control);
FGrid := THackBook(Control);
GetCellWidthHeight;
FFormReport := aFormReport;
aFormReport.DrawOnPageFooter := TRUE;
aFormReport.GridTop := THackFormReport(aFormReport).OffsY + Control.Top;
aFormReport.GridHeight := Control.Height;
liGridTitleHeight := 0;
NextTop := Control.Top + THackFormReport(aFormReport).OffsY;

if FUserDataset = nil then

FUserDataset := TRMUserDataset.Create(nil);
if FList = nil then

FList := TStringList.Create;

THackFormReport(aFormReport).CanSetDataSet := False;
FList.Clear;
FUserDataset.OnCheckEOF := OnUserDatasetCheckEOF;
FUserDataset.OnFirst := OnUserDatasetFirst;
FUserDataset.OnNext := OnUserDatasetNext;
FUserDataset.OnPrior := OnUserDatasetPrior;
aFormReport.Report.DataSet := FUserDataset;
aFormReport.Report.Onbegin
Band := OnReportbegin
Band;


Leftx := 0;
for i := 1 to liGrid.LastColdo

Leftx := Leftx + liGrid.ColWidthTwips div BookWidth1 * BookWidth + 1;

if (aFormReport.PrintControl = Control) or (Leftx > StrToInt(THackFormReport(aFormReport).FormWidth[0])) then

THackFormReport(aFormReport).FormWidth[0] := IntToStr(Leftx + (THackFormReport(aFormReport).OffsX + Control.Left) * 2);

Leftx := Control.Left + THackFormReport(aFormReport).OffsX;
NextLeft := 0;
if liGrid.FixedRows > 0 then
//表头
begin

for i := 1 to liGrid.FixedRows do

begin

liGridTitleHeight := liGridTitleHeight + liGrid.RowHeight div BookHeight1 * BookHeight + 4;
NextLeft := Leftx;
liPageNo := 0;
liNum := 0;
liPage := aFormReport.Report.Pages[0];
for j := 1 to liGrid.LastColdo

begin

if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then

begin

if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(NextLeft + (liGrid.ColWidthTwips[j]div BookWidth1 * BookWidth + 1)) > THackFormReport(aFormReport).PageWidth) then
// 超宽
begin

liNum := 0;
THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(NextLeft);
Inc(liPageNo);
if liPageNo >= aFormReport.Report.Pages.Count then

begin

THackFormReport(aFormReport).AddPage;
THackFormReport(aFormReport).FormWidth.Add('0');
end;

liPage := aFormReport.Report.Pages[liPageNo];
NextLeft := Leftx;
DrawFixedHeader(i);
end;

end;

MakeOneHeader(i, j);
Inc(liNum);
end;

NextTop :=NextTop + liGrid.RowHeight div BookHeight1 * BookHeight + 4;
end;

end;



if THackFormReport(aFormReport).FormWidth.Count > 1 then

THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(NextLeft);

liPage := Page;
liPageNo := 0;
liNum := 0;
NextLeft := Control.Left + THackFormReport(aFormReport).OffsX;
for i := 1 to liGrid.LastColdo
//表体
begin


if (aFormReport.ScaleMode.ScaleMode <> rmsmFit) or (not aFormReport.ScaleMode.FitPageWidth) then

begin

if (liNum > 0) and (THackFormReport(aFormReport).CalcWidth(NextLeft + (liGrid.ColWidthTwips div BookWidth1 * BookWidth + 1)) >THackFormReport(aFormReport).PageWidth) then
// 超宽
begin

liNum := 0;
{DONE -oArm:超过页宽时越界}
THackFormReport(aFormReport).FormWidth[liPageNo] := IntToStr(NextLeft);
Inc(liPageNo);
if liPageNo >= aFormReport.Report.Pages.Count then

begin

THackFormReport(aFormReport).AddPage;
THackFormReport(aFormReport).FormWidth.Add('0');
end;

liPage := aFormReport.Report.Pages[liPageNo];
NextLeft := Control.Left + THackFormReport(aFormReport).OffsX;
{DONE -oArm:表前n列问题}
end;

end;

MakeOneDetail(i);
Inc(liNum);
end;

if THackFormReport(aFormReport).FormWidth.Count > 1 then

THackFormReport(aFormReport).FormWidth[THackFormReport(aFormReport).FormWidth.Count - 1] := IntToStr(NextLeft);
end;


procedure TRMPrintF1book6.OnReportbegin
Band(Band: TRMBand);
begin

if Band.Typ = btMasterData then

Band.dy :=((THackBook(FGrid).RowHeight[FCurrentRow] div Bookheight1) *Bookheight );
end;


procedure TRMPrintF1book6.OnUserDatasetCheckEOF(Sender: TObject;
var Eof: Boolean);
begin

Eof := FCurrentRow >(THackbook(FGrid).LastRow);
end;


procedure TRMPrintF1book6.OnUserDatasetFirst(Sender: TObject);
begin

FCurrentRow :=1+THackbook(FGrid).FixedRows;
SetMemos;
end;


procedure TRMPrintF1book6.OnUserDatasetNext(Sender: TObject);
begin

Inc(FCurrentRow);
SetMemos;
end;


procedure TRMPrintF1book6.OnUserDatasetPrior(Sender: TObject);
begin

Dec(FCurrentRow);
SetMemos;
end;


procedure TRMPrintF1book6.SetMemos;
var
i,FixCount: Integer;
liView: TRMMemoView;
s,S1: string;
liHeight,Temp: Integer;
cellformat:F1CellFormat;
pRow1, pCol1, pRow2, pCol2:integer;
Procedure FindandSetMemo(RowNo,ColNo:integer;MemoName:String);
var
j:integer;
begin

liHeight := (THackBook(FGrid).RowHeight[RowNo] div Bookheight1) *BookHeight ;
liView := TRMMemoView(FFormReport.Report.FindObject(MemoName));
if liView <> nil then

begin

s := THackBook(FGrid).TextRC[RowNo,ColNo+1];
liView.Memo.Text:= s;
//合并单元格的对齐方式
{DONE -oArm:大于26列出错}
if (ColNo div 26)=0 then

FGrid.Selection:=Chr(65+ColNo)+inttostr(RowNo)
else

FGrid.Selection:=Chr(65+(ColNo div 26))+Chr(65+(ColNo mod 26))+inttostr(FCurrentRow);

FGrid.GetSelection(0,pRow1,pCol1,pRow2, pCol2);
If (pRow1<pRow2) and (pRow1=RowNo) then

begin

Temp:=0 ;
For J:=pRow1 to pRow2do

Temp:=Temp+(THackBook(FGrid).RowHeight[J] div Bookheight1) *BookHeight;
liView.dy:=temp;
end
else

liView.dy:=liHeight;
If (pCol1<pCol2) and (pCol1=ColNo+1) then

begin

Temp:=0 ;
For J:=pCol1 to pCol2do

Temp:=Temp+(THackBook(FGrid).ColWidthtwips[J] div BookWidth1)*BookWidth+1;
liView.dx:=Temp;
end
else

liView.dx:=(THackBook(FGrid).ColWidthtwips[ColNo+1] div BookWidth1)*BookWidth+1;

//对齐方式
FGrid.SetActiveCell(RowNo,ColNo+1);
Cellformat:=FGrid.GetCellFormat;
If CellFormat.AlignHorizontal=F1HAlignCenter then

LiView.pAlignment:=rmtaCenterJustify;
If CellFormat.AlignHorizontal=F1HalignRight then

LiView.pAlignment:=rmtaRightJustify;
If CellFormat.AlignHorizontal=F1HAlignLeft then

LiView.pAlignment:=rmtaLeftJustify;
{//垂直排列}
If CellFormat.AlignVertical=F1VAlignTop then

LiView.pLayout:=rmtlTop;
If CellFormat.AlignVertical=F1VAlignCenter then

LiView.pLayout:=rmtlCenter;
If CellFormat.AlignVertical=F1VAlignBottom then

LiView.pLayout:=rmtlBottom;
//
if CellFormat.AlignHorizontal=F1HAlignGeneral then

if IsNumber(s) then

LiView.pAlignment:=rmtaRightJustify
else

LiView.pAlignment:=rmtaLeftJustify;

//字体
LiView.Font.Name:=CellFormat.FontName;
LiView.Font.Size:=CellFormat.FontSize;
LiView.Font.Color:=CellFormat.FontColor;
Liview.Font.Style:=[];
if CellFormat.FontBold then

Liview.Font.Style:=LiView.Font.style+[fsBold];
if CellFormat.FontItalic then

Liview.Font.Style:=LiView.Font.style+[fsItalic];
if CellFormat.FontUnderline then

Liview.Font.Style:=LiView.Font.style+[fsUnderline];
if CellFormat.FontStrikeout then

Liview.Font.Style:=LiView.Font.style+[fsStrikeOut];
//画表格线
FGrid.GetSelection(0,pRow1,pCol1,pRow2, pCol2);
Liview.prop['FrameTyp']:=RMftNone;
IF RowNo=PRow1 then

If cellformat.BorderStyle[F1TopBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftTop;
IF ColNo+1=PCol1 then

If cellformat.BorderStyle[F1LeftBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftLeft;
IF RowNo=PRow2 then

If cellformat.BorderStyle[F1BottomBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftBottom;
IF ColNo+1=PCol2 then

If cellformat.BorderStyle[F1RightBorder]>0 then

Liview.prop['FrameTyp']:=Liview.prop['FrameTyp']+rmftRight;
end;

end;

begin

FixCount:=0;
for i := 0 to FList.Count - 1do

begin

//处理固定列
{DONE -oArm:处理固定列}
//防止所有页的固定列超过10 采用 Pos函数
S1:=Copy(FList,Pos('$',Flist),Length(Flist)-Pos('$',Flist)+1);
IF S1[1]='$' then

begin

Inc(FixCount);
FindandSetMemo(FCurrentRow,StrToInt(Copy(S1,2,Length(S1)-1))-1,Copy(FList,1,Length(Flist)-2));
end
else

begin

if FixCount<=FFormReport.GridFixedCols then

FindandSetMemo(FCurrentRow,I,FList)
else

FindandSetMemo(FCurrentRow,I-FixCount+FFormReport.GridFixedCols,FList);
end;

end;

end;

Function IsNumber(S:String):boolean;
const
Number=['0'..'9','.'] ;
Var
I,j:integer;
begin

Result:=True;
if s='' then

Result:=False;
j:=0;
For i:=1 To Length(S)do

begin

If not (S in Number) then

begin

Result:=False;
break;
end
else

begin

If S='.' then

j:=j+1;
If j>1 then

begin

Result:=False;
break;
end;

end;

end;

end;


initialization
RMRegisterFormReportControl(TF1book6, TRMPrintF1book6);
{$ENDIF}
end.

 
上面是我写的控件
需要到http://rmachine.myrice.com/index1.html下载
report machine 以及 powerpack(看powerpack的说明)
 
一般预览显示都会比实际打印结果大些
大富翁里讨论过一个打印F1Book的控件,找一找吧
 
arm你的控件能解决我写的打印问题?
代码太长没有细看!
 
F1Book的打印是这样的,他会根据打印机的情况而改变。
 
关于f1book的打印,没有十分好的解决方法.
换个表格控件能不能.xlgrid.
 
怎么没人答复
看来得强制结束了!
 
答案已经发给你了,请查收。
 
接受答案了.
 
后退
顶部