Exporting some Memos

Hi

I am reviving an - almost - ancient application an i have stuck trying to print 3 memos into an xlsx sheet.
Firstly, i tried to pass the Memo.Lines.text as property but the data are displaying all in a line (this is expected)
Afterwards, i tried to use TList<T> example with TStringList for Text but obviously this can't be done (not accepted by compiler).
Probably, the best way is to use a TVirtualDataTable as source for the TFlexReport,  but i din't managed to find any example of how to create/use this class in the documentation or examples given with FlexCel. I want to return a line of the memo for each virtual record. ( Number of lines is unpredicted and the width varies from 5 to many chars)

I would be grateful for any revelant help, link or -much better- code.
Thanks in advance
A.Kyriakos

PS: I know that maybe the export of memo like this, doesn't seem as elegant enough solution but for the moment it will cover the needed functionality.

Hi,
While indeed defining a TVirtualDataTable/TVirtualDataTableState is indeed the "right" solution, in this case it might be a little overkill.

If this is a one-off thing, and the memos don't have millions of lines, the simplest way is to copy those strings into a TArray<SomeRecordWithASingleStringField> and then run the report on that. Something like this:


type
  TData = record
    Data: string;
  end;

procedure DoReport(const memo1: TMemo);
var
  m: TArray<TData>;
  fr : TFlexCelReport;
  i: integer;
begin
  SetLength(m, memo1.Lines.Count);
  for i := Low(m) to High(m) do m.Data := memo1.Lines;

  fr := TFlexCelReport.Create(true);
  try
    fr.AddTable<TData>('memo1', m);
    fr.Run('template.xlsx', 'result.xlsx');
  finally
    fr.Free;
  end;

end;



In the template, you would write <#Memo1.Data> inside a Memo1 range.

But well, while this is the fastest to implement, this solution does have the drawback that the data on the memo is copied into the TArray<TData>
For a more generic solution, indeed defining a VirtualDataTable/VirtualDataTableState is the way to go. Doing it is not too difficult: You need to descend 2 classes from TVirtualDataTable and TVirtualDataTableState, and implement the abstract methods. This will give you a "minimum" DataTable which you can use but which lacks advanced stuff like master detail or the ability to filter the dataset. There is no doc in vcl, but you can read the FlexCel.NET doc in the topic which is similar:
http://www.tmssoftware.biz/flexcel/docs/net/UsingFlexCelReports.pdf
(look at the appendix II). But the simplest is to just ctrl-click in TVirtualDataTable and ctrl-click again to get to the definition: every method is documented. I personally prefer to read the docs directly in the sources, but if you prefer, you can press F1 to get help in TVirtualDataTable/State or read it here:
http://www.tmssoftware.biz/flexcel/hlp/vcl/index.htm?FlexCel.Report.TVirtualDataTable.htm
http://www.tmssoftware.biz/flexcel/hlp/vcl/index.htm?FlexCel.Report.TVirtualDataTableState.htm

I have made a simple demo to show how to use a TVirtualDataSet in this case. You can just reuse the unit UStringListDataProvider in your app.
Get it here:
http://www.tmssoftware.biz/flexcel/samples/stringlisttable.zip

Hi Adrian

Thank you very much for your quick, detailed and specific answer.

A>kyriakos