Generic Dataset report formatting

Hi.

I'm currently converting my code and templates from the old FlexCel VCL v3.6 to the current v7.23. A lot of things changed since then, but fortunately my reports are quite simple and a lot of templates only required minor adjustments.

All reports are based on exporting datasets with templates.

Ironically I'm having problems with the more generic ones, where a full dataset needs to be exported.

In v3.6 I have for example a template like this:

Screenshot 2025-03-04 125010

Here a table called "memRexExp" would be exported as is, with field titles in the first row and data on the subsequent rows.
However, I know that the third column must always be highlighted in green and the fifth must be formatted as a number with 2 decimal places (you can't see this from the screenshot, but the current selected cell has such a formatting).

This works great in v3.6, as you can see here:

Screenshot 2025-03-04 125042

In v7.23 I had to change the template in order to have both titles and data exported (BTW I've also added autowidth feature, which is great!):

Screenshot 2025-03-04 131816

However, the exported document doesn't have my formatting anymore:

Screenshot 2025-03-04 131735

As you can see, the third column isn't green and the fifth column doesn't have decimals.

I read the docs and understood that this is probably the current behavior by design (all the cells will be overwritten with exported data). So, how can I mimic v3.6 behavior in v7.23?

Thanks!

Hi,
I am glad to hear the conversion is going well!

About this change, indeed, the behavior in the new reports is that the cells are overwritten. To fix this you could:

  1. If possible, just change this to a "non-generic" report. Then you can just format the cells as you want.
  2. If not possible, then you can use <#format cell> to format the cells based in say a field name. You can see an example of that in the demo Generic reports (Delphi) | FlexCel Studio for VCL and FireMonkey documentation

As you can see, it formats one column in white and the other in green:

That's because it has the line:

<#if(<#evaluate(mod(column(),2)=0)>;<#format cell(light)>;)>

But it also has the tags:

<#if(<#table.*>="BONAP";<#format cell(blue)>;)><#if(<#table.**>="OrderDate";<#format cell(longdate)>;)>

Look at how "Order Date" has a long date (formatted in spanish here because that's the locale where I run this), different from say Ship Date which has normal formatting.

Note also that we compare table.** to "OrderDate", this means the column name must be "OrderDate" (because 2 * mean column name)

The other one compares table.*to BONAP, and a single * means content, not column name. So this will be blue only if a cell has the "BONAP" text inside. (as is the case if you scroll down below):

This could have of course done also with Excel's conditional formatting, which might be simpler.

Hi Adrian,

Thank you for your answer!

Unfortunately I can't change the report to a non-generic one, at least I think I can't. I have quite a lot of datasets in which the first columns are identical and here is where I want to apply a common formatting, but the rest of the columns can vary quite a lot, both in quantity and in content types.

I'm ok with the default formatting of that "extra" columns and this is primarily the reason I'd like to use a single generic template, it'll save me a lot of effort not having to create a specific template for each table. However, some of the common starting columns must be formatted in a specific way, so I need this feature.

I think the field name could be a solution, I have to check but quite certainly the common fields' names are the same.

Is it possible, in case I can't use the field name, to apply format based on column number?

Yes, indeed you can use the column number. The first expression (the one that formats even columns in green) does something like that:

<#if(<#evaluate(mod(column(),2)=0)>;<#format cell(light)>;)>

You could do instead:

<#if(<#evaluate(column()=2)>;<#format cell(light)>;)>

To format only column number 2.

Oh, yes! I could have figured that out :wink:

Thank you, I'll try asap.

Hi.

Just a simple (I hope) question: is it possible to apply logical operators inside #if or #evaluate? I've tried in various ways but no one worked.

What I want to do is apply a format to a range of columns, lets say from the 5th to the 8th. I've tried:

<#Elenco.*><#if(<#evaluate(column()>=5 and column()<=8)>;<#format cell(zerodec)>;)>

or

<#Elenco.*><#if(<#evaluate(column()>=5)> and <#evaluate(column()<=8)>;<#format cell(zerodec)>;)>

Both give me an error at the space just before the "and". If I leave out spaces I get the same error but on the letter "a" of the word "and".

I've also tried a shortcut like this:

<#Elenco.*><#if(<#evaluate(5<=column()<=8)>;<#format cell(zerodec)>;)>

This doesn't give me an error, but it doesn't work anyway.

How can I solve this?

What goes inside "Evaluate" is a standard Excel formula: anything you can write in Excel you can write there (And that also applies to the if).

In Excel you would use "OR" and "AND" functions:

So you could write:

<#if(<#evaluate(and(column()>=5,column()<=8))> ...

See FlexCel Reports Tag Reference. | FlexCel Studio for VCL and FireMonkey documentation
and
FlexCel Reports Designer Guide | FlexCel Studio for VCL and FireMonkey documentation

Thank you Adrian, worked as expected.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.