This is my standard report class:
Report := CreateFlexCel;
try
Report.GetInclude := GetIncludes;
TemplateStream := Template(ReportName);
Model.AddSubModel['sagah.aluno'];
List := Model.DataViewParam['aluno.all', Param].AsCriteria.List<TEntityContatoAluno>;
Report.AddTable<TEntityContatoAluno>('data', List);
Report.Run(TemplateStream, AStream);
finally
TemplateStream.Free;
Report.Free;
List.Free;
end;
where:
- I get my excel template that is a resource compiled to my exe,
- get a TList<> of the entities that I am going to use for the report
- and execute the report.
This works very well.
But now I got a different situation and my framework is stuck in the concept above.
I have tried the following, that is a change on the code above, but resulting the SAME stream that will be used for preview:
procedure TNaharReportSagahKitMatricula.InternalExecute(AStream: TStream);
var
Report: TFlexCelReport;
TemplateStream: TStream;
DataView: INaharDataView;
List: TList<TEntityContatoAluno>;
Aluno: TEntityContatoAluno;
Data: TList<TEntityContatoAluno>;
ReportStream: TMemoryStream;
begin
inherited;
try
// Report.GetInclude := GetIncludes;
Model.AddSubModel['sagah.aluno'];
List := Model.DataViewParam['aluno.all', Param].AsCriteria.List<TEntityContatoAluno>;
for Aluno in List do
begin
Report := CreateFlexCel;
TemplateStream := Template('sagah.cadastroaluno');
Data := TList<TEntityContatoAluno>.Create;
Data.Add(Aluno);
ReportStream := TMemoryStream.Create;
Report.AddTable<TEntityContatoAluno>('data', Data);
Report.Run(TemplateStream, ReportStream);
AStream.Position := AStream.Size;
ReportStream.SaveToStream(AStream);
ReportStream.SaveToFile(Aluno.Nome);
ReportStream.Free;
Data.Free;
TemplateStream.Free;
Report.Free;
end;
finally
List.Free;
end;
end;
I am not being carefull on this code, I just want to test the concept.
The thing here is that i need to have that
TemplateStream := Template('sagah.cadastroaluno');
that brings the excel template as a memory stream executed for diferent templates.
AND I need it done for EACH entity on the list.
So i have wondered passing a TList<> with only ONE entity and execute the same data by flexcel with different templates and concatenating the result on the memory stream.
I could have something like
data1:
report1 + report2 + report3
data2:
report1 + report2 + report3
and so on...
IN my framework the resulting memory stream is then attached to the previewer for showing on user screen.
But what I see always is only the first report generated. It does go thru all the reports and concatenate on the stream. But I am not aware of how many reports can be concatenated on the same stream BEFORE going to preview.
Please HELP
Eduardo