fast report(10分)

  • 主题发起人 主题发起人 蓝蒙
  • 开始时间 开始时间

蓝蒙

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么应用fast report中的脚本语言???
我想把:a:=copy(datetostr(date),2,1)+copy(datetostr(date),4,1)
打印出来
 
把它变成字符串试一下?
 
[Copy([qryData."WASHMETHOD"],1,8)]
 
Procedure TurnToExcel(TmpDBGrid:TDBGrid);
var
MyExcel: Variant;
WorkBook: OleVariant;
WorkSheet: OleVariant;
i,j:integer;
xlsfilename :string;
Savedialog1 :TSaveDialog;
begin
if Application.MessageBox('确认导出到Excel?',App_caption,MB_ICONQUESTION+MB_YESNO)=mrno then
Abort;
SaveDialog1 :=TSaveDialog.create(Application);
SaveDialog1.Filter := 'Excel文件(*.xls)|*.XLS';
if savedialog1.Execute then
if savedialog1.FileName <>'' then
begin
xlsfilename :=savedialog1.FileName;
try
MyExcel:=CreateOleObject('Excel.Application');
MyExcel.Application.WorkBooks.Add;
MyExcel.Caption:='将数据导入到EXCEL表中';
MyExcel.Application.Visible:=false;
WorkBook:=MyExcel.Application.workbooks[1];
worksheet:=workbook.worksheets.item[1];
except
Application.MessageBox('EXCEL不存在!',App_caption,MB_ICONERROR+MB_OK);
Savedialog1.Free;
workBook.Saved := True;
WorkBook.close;
MyExcel.Quit;//释放VARIANT变量
MyExcel:=Unassigned;
end;
i:=1;
Frm_system_progress :=TFrm_system_progress.create(Application);
Try
with TmpDBGrid.DataSource.DataSet do
begin
Open;
DisableControls;
with Frm_system_progress.ProgressBar_temp do
begin
min :=0;
max :=TmpDBGrid.Columns.Count*recordcount;
Position :=0;
end;
Frm_system_progress.label_progress.caption :='正在导出到Excel...';
Frm_system_progress.Show;
Frm_system_progress.update;
for j:=0 to TmpDBGrid.Columns.Count-1 do
begin
if TmpDBGrid.Columns[j].Visible=true then
worksheet.cells[1,j+1]:=TmpDBGrid.Columns[j].Title.Caption;
end;
First;
while not Eof do
begin
inc(i);
for j:=0 to TmpDBGrid.Columns.Count-1 do
begin
if TmpDBGrid.Columns[j].Visible=true then
begin
worksheet.cells[i,j+1].NumberFormatLocal :='@';
worksheet.cells[i,j+1]:=TmpDBGrid.Columns[j].Field.AsString ;
Frm_system_progress.ProgressBar_temp.StepIt;
end;
end;
next;
end;
EnableControls;
end;
WorkBook.saveas(XlsFileName);
Frm_system_progress.ProgressBar_temp.position :=TmpDBGrid.Columns.Count*TmpDBGrid.DataSource.DataSet.RecordCount;
Application.MessageBox('导出到Excel成功!',App_caption,MB_ICONINFORMATION+MB_OK);
Frm_system_progress.Free;
MyExcel.Quit;
MyExcel := Unassigned;
Savedialog1.Free;
except
Application.MessageBox('导出到Excel失败!',App_caption,MB_ICONWARNING+MB_OK);
workBook.Saved := True;
WorkBook.close;
MyExcel.Quit;//释放VARIANT变量
MyExcel:=Unassigned;
Frm_system_progress.Free;
Savedialog1.Free;
end;
end;

end;
 
数据网格自动适应宽度///////源代码开始
uses
Math;

function DBGridRecordSize(mColumn: TColumn): Boolean;
{ 返回记录数据网格列显示最大宽度是否成功 }
begin
Result := False;
if not Assigned(mColumn.Field) then Exit;
mColumn.Field.Tag := Max(mColumn.Field.Tag,
TDBGrid(mColumn.Grid).Canvas.TextWidth(mColumn.Field.DisplayText));
Result := True;
end; { DBGridRecordSize }

function DBGridAutoSize(mDBGrid: TDBGrid; mOffset: Integer = 5): Boolean;
{ 返回数据网格自动适应宽度是否成功 }
var
I: Integer;
begin
Result := False;
if not Assigned(mDBGrid) then Exit;
if not Assigned(mDBGrid.DataSource) then Exit;
if not Assigned(mDBGrid.DataSource.DataSet) then Exit;
if not mDBGrid.DataSource.DataSet.Active then Exit;
for I := 0 to mDBGrid.Columns.Count - 1 do begin
if not mDBGrid.Columns.Visible then Continue;
if Assigned(mDBGrid.Columns.Field) then
mDBGrid.Columns.Width := Max(mDBGrid.Columns.Field.Tag,
mDBGrid.Canvas.TextWidth(mDBGrid.Columns.Title.Caption)) + mOffset
else mDBGrid.Columns.Width :=
mDBGrid.Canvas.TextWidth(mDBGrid.Columns.Title.Caption) + mOffset;
mDBGrid.Refresh;
end;
Result := True;
end; { DBGridAutoSize }
///////源代码结束

///////使用示例开始
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
DBGridRecordSize(Column);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
DBGridAutoSize(DBGrid1);
end;
 
>>以序号为横坐标,平均制为纵坐标,画出图表
>>能否将几个SERIES合为一起呢?
可以的:在DBChart上放三个Series,在DBChart的可视化编辑窗口中将其中两个的DataSource设为DataSet,
指定X为序号字段,指定Y分别为X1和X2,把这两个的Active置为False;把第三个Series的
DataSource设为Function,Average,把那两个加进来就行了

>>但要在图表中画出几条平行线,用于标记是否超出警戒范围,还要在线的旁边加上注释,并且需要动态生成
在DBChart的OnAfterDraw里(以一条警戒线为例):
procedure TForm1.DBChart1AfterDraw(Sender: TObject);
const
Danger: Double = 10.5;//警戒水位
DColor: TColor = clRed;//平行线的颜色
DInfo: String = '警戒线';//注释信息
var
X1, X2, Y: Longint;
R: TRect;
begin
with Series1 do begin//Series1为一TLineSeries
X1 := CalcXPosValue(0);
X2 := CalcXPosValue(MaxXValue);
Y := CalcYPosValue(Danger);
end;
with DBChart1.Canvas do begin
Pen.Color := DColor;
MoveTo(X1, Y);
LineTo(X2, Y);
Pen.Color := clInfoText;
Brush.Color := clInfoBk;
R := Rect((X1 + X2) div 2, Y - TextHeight(DInfo), (X1 + X2) div 2
+ TextWidth(DInfo) + 4, Y + 4);//显示注释的矩形框,具体大小和位置根据实际情况确定
FillRect(R);
TextOut(R.Left + 2, R.Top + 2, DInfo);
end;
end;
比例缩放用DBChart1.View3DOptions.Zoom控制。打印用DBChart.Print。

>>并且不列入图表的生成数据中
什么意思?
 
Example Pie-Series
Suppose the Series we added was a Pie Series. We could populate the Series in the following way. For the following code to work we should leave the Series name as its default of Series1.

Place a TButton on your Form and go to the OnClick event .
Copy the following code at the Button1.OnClick event:

With Series1 do
Begin
Add( 40, 'Pencil' , clRed ) ;
Add( 60, 'Paper', clBlue ) ;
Add( 30, 'Ribbon', clGreen ) ;
end;

以上是折自teechart.hlp中 chart例子
 
后退
顶部