Change SheetName in TFlexCelReport

Hi,

how can I chage the name of a (the one and only in this case) sheet in a report? One idea is, after the report run, to open the file again in a TXlsFile object, but perhaps there is an easier way.

Thanks,
Micha

Sorry for the question. I just read the documentation which says that tags can also be applied on sheet names.

Thanks for that great product. :-)
Micha

Well, the simplest way is just to name the sheet with some tag. For example, you could name the sheet:

<#MySheetName>

And then in code do:
report.SetValue('MySheetName', 'Potato');

This will end up with the sheet named potato. A sheet name is limited to 32 characters long, so you can't write very large expressions in the sheet name, but you can define the expression in the config sheet if you need more than a simple tag.

If this isn't enough, you could use the AfterGenerateSheet event to do the customization there.

And finally, if you want to do even more customization, you can run the report in a TXlsFile object directly, so you don't have to open the file again.

You can use code like this:

xls:=TXlsFile.Create('template.xlsx', true);
try
  report := TFlexCelReport.Create(true);
  try
    report.setthings();
    report.Run(xls);
    xls.DoExtraStuff; //set the sheet name here
    xls.Save('result.xlsx');
  finally
    report.Free;
  end;
finally
  xls.Free;
end;


opening the template in a TXlsFile object, then running the report in the TXlsFile object, then saving the TXlsFile object in a result file is the same as running the report directly in the template and the result.


oopsss... to late :)

Indeed, the easiest is to use tags in the sheet name.