Report Builder FastReport .Net User Guide: Changing the Report Format

FastReport .Net is a full-featured Windows Forms, ASP.NET and MVC report analysis solution. Using FastReport .NET can create .NET reports independent of applications. At the same time, FastReport .Net supports 14 languages ​​such as Chinese and English. You can make your products truly international.

In this section, we investigate the following questions:

  • change the appearance of an object;
  • change the format of printed values;
  • Automatically change the appearance of an object when certain conditions are met;
  • hide unnecessary values;
  • Even highlight rows of data with different colors.
border and padding

Most report objects have borders and fills. To work with these properties, use the "Border and Fill" toolbar:

3

The object's border consists of four lines. Each line can have a different width, color and style. The buttons on the toolbar affect all lines of the frame. 

button to display a dialog where each line can be set individually:

4

To deal with padding, there are two buttons on the toolbar. 

button allows to choose a color for the solid fill type.

button displays a dialog allowing to choose between different fill types:

5

text formatting

To change the appearance of the "Text" object, use the "Text" toolbar:

6

Set Styles

To set the appearance of an object, you can use styles. A style is a collection of the following properties:

  • boundary
  • filling
  • font
  • text color

A list of styles is stored in a report. You can use the "Report|Styles..." menu or the "Styles" toolbar 

 button to control it:

7

You can style an object in the following ways:

  • Set the "Style" property in the "Properties" window;
  • Using the "Style" toolbar:

8

When you style an object, the object's appearance changes according to the style settings. When you change a style setting, objects with that style will change automatically.

data formatting

In order to print text data in reports, the "Text" object is used. It uses a default format for all data from the data source. For example, a data source column of type "DateTime" would be printed as follows (this depends on your system's locale):

11.10.2008 18:04:52

If you only need to print the date part, you have to format the data. To do this, right-click on the "Text" object to display its context menu. In the menu, select the "Format..." item. You will see the format editor window:

9

You can choose one of the available formatting types, or set your own formatting strings. To do this, select the "Custom" format. If the "Text" object contains several data columns or expressions, you can select an appropriate format for each of them. To do this, select Expression at the top of the window, then Format:

10

You can also format data using the String.Format method. Get help on this method in MSDN.

Today is [String.Format("{0:d}", [Date])]
highlight

Changes the appearance of the "Text" object according to the given condition. If an object has a negative value, it can be highlighted in red. This feature is called "conditional highlighting". To set it, select the "Text" object and click on the "Text" toolbar 

button, you will see the following dialog window: 

1

One or several conditions can be defined and styled for each condition. A style can contain one or several settings:

  • filling
  • text color
  • font
  • object visibility

You can indicate which settings need to be changed when the conditions are met, and check them using checkboxes. By default, a new style contains one setting - text color.

To create a new condition, click the "Add" button. You'll see an expression editor:

10

Here, you can write any expression that returns a Boolean result. In many cases you will use the "Value" variable, which contains the currently printed value.
Let's see the following example: We have a "Text" object in which we print the stock quantity of a product:

[Products.UnitsInStock]

In the case of product quantity = 0, the object is painted red, so the following conditions need to be created:

Value == 0

In the given case, we have used the "Value" variable, which has a printed value. If there are several expressions in an object, then this variable will have the value of the last expression. You can use a data column instead of "Value":

[Products.UnitsInStock] == 0
The expression is written in C# style. This is so, if the chosen report language is C#. For VisualBasic.Net you must use the single "=" sign. The report language can be changed in the "Report|Options..." menu.

Configure the style for a given condition to only use padding and select red:

11

When printing an object with a value of zero, it will be red. If the SKU is less than 10, it must be printed yellow. To do this, open the condition editor and click the "Add" button. The second condition would be something like this:

Value < 10

In case several conditions are indicated, FastReport checks all of them, starting from the first one. If a certain condition is met, FastReport applies its style settings to the object, and the process stops. It is important to put the conditions in the correct order.

1. Value == 0   2. Value < 10 
hide zero values

"Text" objects have a "HideZeros" property that can be used to hide zero values. The following is an example:

Total elements: [CountOfElements] 

If the value of the variable CountOfElements is equal to 0 and the property HideZeros is set to "true", then the object will be printed as follows:

Total elements:

"Text" objects also have a "HideValue" property that can be used to hide the value of an expression equal to a given value. If the attribute value is "0", then all zero fields will be hidden. This property can also be used to hide zero dates. Typically, it's a date like "1.1.0001" or "1.1.1900". In this case, the value of the "HideValue" property must look like this:

1.1.1900 0:00:00

As you can see, since date values ​​in .Net also contain time in addition to the date, you also need to indicate the time.

<img src="https://image.evget.com/2023/07/07/3297pc3jvjjl0ame22.png" width="350" height="125" />

The "NullValue" property of the "Text" object allows to print some text instead of a null value. It is often used to print dashes instead of nulls. Let's look at an object with the following content:

Total elements: [CountOfElements]

If the value of the variable CountOfElements is null and the property NullValue is set to ------, then the object will be printed as follows:

Total elements: -- 
hide duplicates

"Text" objects have a "Duplicates" property that allows control over how duplicate values ​​are printed. This property can be used if the "Text" object is on the "Data" band. Values ​​are considered duplicates if they are printed in nearby data rows.

The "Duplicates" property can have one of the following values:

  • show - Show duplicate values ​​(default)
  • hidden - hides objects with duplicate values
  • Clear - Clears the object's text, but displays the object
  • Merge - Merge several objects with the same value

The difference between these modes is shown in the figure below:

12

Highlight odd/even data rows

To improve the appearance of the report, you can highlight even rows of data with a different color. This can be achieved by using the "EvenStyle" property of the strap or its object. This attribute contains a style name that will be used to highlight even-numbered rows:

It is preferable to use the "EvenStyle" property of the object instead of the band. This avoids possible problems when exporting the report.、

In order to configure highlighting, do the following:

Defines the style used to highlight rows. This can be done in the "Report|Styles... " menu.

Indicate the name of the new style in the "EvenStyle" property of the band or its object.
By default, the object only uses the padding properties of the style given in the "EvenStyle" property. This behavior is defined in the "EvenStylePriority" property -- defaults to "UseFill". If you need to use the rest of the style parameters, set this property to "UseAll".

A prepared report, using this technique, could look like this:

13

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/132404582