EugeneBoss3 Цитата: Может есть реализация? Пример, плиз.
Код правда скриптового движка, но по сути такой-же как в Delphi
[more]
Код: program FRM5;
var
XLS: TXLSReadWriteII2;
QR: TpFIBQuery;
DY, DM, DD: word;
repname, fname: string;
ls, j: integer;
FGRP: integer;
sj: integer;
DS: TpFIBDataset;
DS2: TpFIBDataset;
s1: extended;
s2: extended;
s3: extended;
////////////////////////////////////////////////////////////////////////////////
procedure IncJ;
begin
j := j + 1;
XLS.Sheet[0].Range.Items[0, j, ls, j].Copy(0, j + 1);
end;
////////////////////////////////////////////////////////////////////////////////
// Начало программы
////////////////////////////////////////////////////////////////////////////////
begin
repname := ReadVariable('CURRENT_REPORT_NAME');
XLS := TXLSReadWriteII2.Create(SELF);
QR := TpFIBQuery.Create(SELF);
QR.Database := DATABASE;
QR.Transaction := TRANSACTION;
QR.SQL.Text := 'SELECT REP_DATA FROM IBR$REPORTP WHERE REP_NAME =
RM';
QR.ExecWP([repname]);
DecodeDate(Date, DY, DM, DD);
fname := 'ФОРМА5_' + Format('%2.2d', [DD]) + Format('%2.2d', [DM]) +
Format('%4.4d', [DY]);
fname := ExpandFileName('.\REPORTS\' + ChangeFileExt(fname, '.xls'));
QR.FN('REP_DATA').SaveToFile(fname);
XLS.FileName := fname;
XLS.Read;
if not OpenAllDatasets(DATABASE, repname, True) then Exit;
DS := DatasetByName('PLAN');
DS2 := DatasetByName('DATA');
try
XLS.Sheets[0].AsString[5, 1] := FormatDateTime('dd.mm.yyyy', ReadVariable('TO_DATE'));
s1 := 0;
s2 := 0;
s3 := 0;
j := 12;
ls := 7;
XLS.Sheet[0].AsString[2, 3] := DS2.FN('NUM').AsString;
if DS2.FN('DAT').IsNull then
XLS.Sheet[0].AsString[2, 4] := ''
else
XLS.Sheet[0].AsDateTime[2, 4] := DS2.FN('DAT').AsDateTime;
XLS.Sheet[0].AsString[2, 5] := DS2.FN('NAME_SMALL').AsString;
if DS2.FN('FDAT').IsNull then
XLS.Sheet[0].AsString[2, 6] := ''
else
XLS.Sheet[0].AsDateTime[2, 6] := DS2.FN('FDAT').AsDateTime;
XLS.Sheet[0].AsFloat[2, 7] := DS2.FN('SUMDOG').AsFloat;
XLS.Sheet[0].AsFloat[2, 8] := DS2.FN('ACTOPLT').AsFloat;
XLS.Sheet[0].AsFloat[2, 9] := DS2.FN('SUMOPLT').AsFloat;
FGRP := 0;
//Основной отчет
while not DS.EOF do
begin
with XLS.Sheets[0] do
begin
IncJ;
sj := j;
AsString[0, j] := DS.FN('NPP').AsString;
AsString[1, j] := DS.FN('NAIM').AsString;
if DS.FN('PERC').IsNull then AsString[2, j] := '' else AsFloat[2, j] := DS.FN('PERC').Value;
if DS.FN('PSUM').IsNull then AsString[3, j] := '' else AsFloat[3, j] := DS.FN('PSUM').Value;
if DS.FN('PERF').IsNull then AsString[4, j] := '' else AsFloat[4, j] := DS.FN('PERF').Value;
if DS.FN('FSUM').IsNull then AsString[5, j] := '' else AsFloat[5, j] := DS.FN('FSUM').Value;
if DS.FN('OTKL').IsNull then AsString[6, j] := '' else AsFloat[6, j] := DS.FN('OTKL').Value;
if DS.FN('PTKL').IsNull then AsString[7, j] := '' else AsFloat[7, j] := DS.FN('PTKL').Value;
if DS.FN('BOLD').AsInteger = 1 then
XLS.Sheet[0].Range.Items[0, j, ls, j].FontStyle := [xfsBold]
else
XLS.Sheet[0].Range.Items[0, j, ls, j].FontStyle := [];
if DS.FN('COLOR').AsInteger = 1 then
XLS.Sheet[0].Range.Items[0, j, ls, j].FillPatternForeColor :=xcBrightGreen;
if DS.FN('GRP').AsInteger = 1 then FGRP := FGRP + 1
else if FGRP <> 0 then
begin
XLS.Sheets[0].Rows.AddIfNone_(j - FGRP, j - 1 );
XLS.Sheets[0].GroupRows(j - FGRP, j - 1, True);
FGRP := 0;
end;
end;
DS.Next;
end;
j := j + 1;
XLS.Sheets[0].Rows.AddIfNone_(j, j);
XLS.Sheets[0].DeleteRows(j,j);
XLS.Sheets[0].SheetProtection := [];
XLS.Write;
ShellExecute(Application.Handle, 'open', fname, '', '', SW_SHOWMAXIMIZED);
finally
XLS.Free;
QR.Free;
end;
end.