G
goodhq
Unregistered / Unconfirmed
GUEST, unregistred user!
查询时,SELECT 一些金额时,要求精确到小数点后两位,就是0,也得是0.00
在DBGRID上显示可以修改QUERY1列的DISPLAYFORMAT=0.00,所以DBGRID显示是正常的,
但是打印时,却仍然是SELECT的值,不会在整数金额后补.00.当然如果是手工报表的话,
也可以以类似的方法修改DISPLAYFORMAT=0.00,但是这样太麻烦了。所以我想如果可以在
动态报表里修改那是最好的。请各位高手指教。
下面是我的打印代码:用FASTREPORT控件。
procedure TForm1.Button1Click(Sender: TObject);
var
v: TfrView;
b: TfrBandView;
Page: TfrPage;
i1,i2:integer;
iwidth:array[0..30] of integer;
//字段宽度
icol:integer;
fieldname:string;
begin
if query1.Active=false then
abort;
if query1.RecordCount<1 then
abort;
icol:=dbgrd.FieldCount;
for i1:=1 to icoldo
iwidth[i1]:=dbgrd.Columns[i1-1].Width;
iwidth[0]:=20;
frReport1.Pages.Clear;
frReport1.Pages.Add;
// create page
Page := frReport1.Pages[0];
b := TfrBandView.Create;
// create Title band
b.SetBounds(0, 20, 0, 40);
// position and size in pixels
b.BandType := btReportTitle;
// (only Top and Height are significant
Page.Objects.Add(b);
// for the band)
v := TfrmemoView.Create;
// create memo
v.SetBounds(20, 20, 200, 36);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter;
// another way to access properties
v.Prop['Font.Style'] := 2;
v.Prop['Font.name'] := '宋体';
v.Prop['Font.size'] := 20;
v.Memo.Add('kkkkkkkkkk' );
Page.Objects.Add(v);
b := TfrBandView.Create;
// create MasterData band
b.SetBounds(0, 80, 0, 20);
b.BandType := btMasterheader;
frDBDataSet1.DataSet:=query1;
frReport1.Dataset:=frDBDataSet1;
b.Dataset := 'frDBDataSet1';
// band's dataset
Page.Objects.Add(b);
i2:=20;
for i1:=1 to icoldo
begin
v := TfrmemoView.Create;
// create data field
v.SetBounds(i2+iwidth[i1-1], 80, iwidth[i1], 20);
v.Prop['Font.name'] := '宋体';
v.Prop['Font.size'] := 9;
v.Prop['Font.Style'] := 2;
i2:=i2+iwidth[i1-1];
v.memo.Add(dbgrd.columns[i1-1].title.caption);
v.FrameTyp :=15;
Page.Objects.Add(v);
end;
b := TfrBandView.Create;
// create MasterData band
b.SetBounds(0, 120, 0, 20);
b.BandType := btMasterData;
b.Dataset := 'frDBDataSet1';
// band's dataset
Page.Objects.Add(b);
i2:=20;
for i1:=1 to icoldo
begin
v := TfrmemoView.Create;
// create data field
v.SetBounds(i2+iwidth[i1-1], 120, iwidth[i1], 20);
v.Prop['Font.name'] := '宋体';
v.Prop['Font.size'] := 9;
i2:=i2+iwidth[i1-1];
fieldname:='[query1.'+'"'+query1.fieldlist.strings[i1-1]+'"'+']';
v.memo.Add(fieldname);
v.FrameTyp :=15;
Page.Objects.Add(v);
end;
frReport1.ShowReport;
end;
在DBGRID上显示可以修改QUERY1列的DISPLAYFORMAT=0.00,所以DBGRID显示是正常的,
但是打印时,却仍然是SELECT的值,不会在整数金额后补.00.当然如果是手工报表的话,
也可以以类似的方法修改DISPLAYFORMAT=0.00,但是这样太麻烦了。所以我想如果可以在
动态报表里修改那是最好的。请各位高手指教。
下面是我的打印代码:用FASTREPORT控件。
procedure TForm1.Button1Click(Sender: TObject);
var
v: TfrView;
b: TfrBandView;
Page: TfrPage;
i1,i2:integer;
iwidth:array[0..30] of integer;
//字段宽度
icol:integer;
fieldname:string;
begin
if query1.Active=false then
abort;
if query1.RecordCount<1 then
abort;
icol:=dbgrd.FieldCount;
for i1:=1 to icoldo
iwidth[i1]:=dbgrd.Columns[i1-1].Width;
iwidth[0]:=20;
frReport1.Pages.Clear;
frReport1.Pages.Add;
// create page
Page := frReport1.Pages[0];
b := TfrBandView.Create;
// create Title band
b.SetBounds(0, 20, 0, 40);
// position and size in pixels
b.BandType := btReportTitle;
// (only Top and Height are significant
Page.Objects.Add(b);
// for the band)
v := TfrmemoView.Create;
// create memo
v.SetBounds(20, 20, 200, 36);
v.BandAlign := baWidth;
v.Prop['Alignment'] := frtaCenter;
// another way to access properties
v.Prop['Font.Style'] := 2;
v.Prop['Font.name'] := '宋体';
v.Prop['Font.size'] := 20;
v.Memo.Add('kkkkkkkkkk' );
Page.Objects.Add(v);
b := TfrBandView.Create;
// create MasterData band
b.SetBounds(0, 80, 0, 20);
b.BandType := btMasterheader;
frDBDataSet1.DataSet:=query1;
frReport1.Dataset:=frDBDataSet1;
b.Dataset := 'frDBDataSet1';
// band's dataset
Page.Objects.Add(b);
i2:=20;
for i1:=1 to icoldo
begin
v := TfrmemoView.Create;
// create data field
v.SetBounds(i2+iwidth[i1-1], 80, iwidth[i1], 20);
v.Prop['Font.name'] := '宋体';
v.Prop['Font.size'] := 9;
v.Prop['Font.Style'] := 2;
i2:=i2+iwidth[i1-1];
v.memo.Add(dbgrd.columns[i1-1].title.caption);
v.FrameTyp :=15;
Page.Objects.Add(v);
end;
b := TfrBandView.Create;
// create MasterData band
b.SetBounds(0, 120, 0, 20);
b.BandType := btMasterData;
b.Dataset := 'frDBDataSet1';
// band's dataset
Page.Objects.Add(b);
i2:=20;
for i1:=1 to icoldo
begin
v := TfrmemoView.Create;
// create data field
v.SetBounds(i2+iwidth[i1-1], 120, iwidth[i1], 20);
v.Prop['Font.name'] := '宋体';
v.Prop['Font.size'] := 9;
i2:=i2+iwidth[i1-1];
fieldname:='[query1.'+'"'+query1.fieldlist.strings[i1-1]+'"'+']';
v.memo.Add(fieldname);
v.FrameTyp :=15;
Page.Objects.Add(v);
end;
frReport1.ShowReport;
end;