4. Varianta skriptu s použitím Range |
Top Previous Next |
Níže je uvedena modifikace skriptu s využitím property Range a metody QueryToCells
procedure OnBeforeReport(Sender : TReportProperty); var Query : TQuery; begin Sheet.BeginUpdate; Sheet.ClearMergedCells; Sheet.RowCount:=3; Sheet.ColCount:=6; Sheet.FixedRows:=2;
Query:=TQuery.Create(nil); with Query do try DatabaseName :=DefaultDatabaseName; SQL.Text:='select mena_id,(select nazev from dba.gstaty where id_stat=(select stat_id from dba.gmeny where mena_id=id_mena)) as nazev '+ 'from dba.gkurzy where stat=''cz'' group by mena_id'; Open; Sheet.Range['B3'].QueryToCells:=Query; With Sheet.Range['B3:'+'D'+IntToStr(Sheet.RowCount-1)] do begin Background:=$00bd814f; Font.Color:=clWhite; OnDblClick:=@MenaDblClick; MarginRight:=$00bd814f; Tag:=1; end; finally Free; end;
Sheet.EndUpdate; end;
procedure DrillMe( mena : string; aRow : integer ); var Query : TQuery; r : integer; flgCollapse : boolean; begin Sheet.BeginUpdate;
//Collapse flgCollapse:=false; r:=aRow+1;
while (Sheet.CellProperty[2,r].Tag=0) and (r<Sheet.RowCount) do begin flgCollapse:=True; Sheet.DeleteRow(r); end; if flgCollapse then begin Sheet.EndUpdate; Exit; end;
// expand Query:=TQuery.Create(nil); with Query do try DatabaseName :=DefaultDatabaseName; SQL.Text:='select top 5 dne,koef from dba.gkurzy where mena_id=:mena and stat=''cz'' order by dne desc'; Params.ParamByName('mena').AsString:=mena; Open;
r:=aRow+1; while Sheet.ColCount-1<3 do Sheet.InsertCol(Sheet.ColCount-1);
while not Query.Eof do begin Sheet.InsertRow(r);
Sheet.Cells[3,r]:=Query.FieldByName('dne').AsString; Sheet.Cells[4,r]:=Query.FieldByName('koef').AsString;
Sheet.CellProperty[3,r].Background:=$00EAEAEA; Sheet.CellProperty[4,r].Background:=$00EAEAEA;
//inc(r); Query.Next; end;
finally Free; end; Sheet.EndUpdate; end;
procedure MenaDblClick(Sender : TCellProperty); begin DrillMe(Value,Sheet.Row); end;
begin end. |