How to make a tree dataset in FineReport to realize the organization tree report

1. Problem description

FineReport , in the organization tree report, the organization tree report is realized by id and parent id. If there are many levels, it will be cumbersome to set filter conditions and shapes for each cell, so FineReport provides a special data set - tree The data set can be automatically recursed out of the hierarchy with simple settings, and it is convenient to realize the organization tree report as shown below:

Figure 1

 

Figure II


2.  FineReport build tree

2.1 Create a new report and add a dataset

Create a new workbook, add the data set ds1 to take out the original data, and the SQL statement is SELECT * FROM company department.

2.2 Defining a tree dataset

1) Build tree based on parent field

Use case: The original table structure conforms to the ID and parentID structure. We can generate a tree through the parent ID field and add a tree dataset, as shown below:

 


2) Build the tree according to the data length

Use case: All IDs in the original table structure are in one column, and there is no parent ID field, but the IDs are regular, the length of each group is the same, and the first N digits of the child are the parent number, add a tree dataset, As shown below:

 


2.3 Preview data

Previewing the tree data set, you can see that the recursive tree data has been automatically generated, FR_GEN_0 is the highest level, and it goes down in sequence, as follows:


3. Example 1 Vertical organization tree

Drag the corresponding data column into the cell as shown in the following figure, and set the left parent of cell A2 to A1 and the left parent of cell A3 to A2:


 

3.1 Conditional properties

With the above preview data, you can see that starting from the second floor FR_GEN_1, there will be blank data. This is because the data stored in the database has the department name and department ID of the upper-level department itself, and the department level of the upper-level department will be A lower level, for example, the first line of the above data is the headquarters. Although there are sub-departments under the headquarters, the database still needs to store the department name and department ID of the headquarters department. The level corresponding to the headquarters is level one, then its corresponding There is only FR_GEN_0 layer in the data record line, and the following two layers, FR_GEN_1 and FR_GEN_2, will have no data and will be displayed as blank.

在模板制作过程中,从第二层级开始就会有空白数据,需要将空白数据隐藏掉,选中A2和A3单元格,添加条件属性,当数据为空时隐藏该行,如下图:


注:如果组织结构的层级结构不确定,即有的层级有子层,有的层级没有子层时,其组织树报表的实现方式请查看不规范组织树报表

3.2 其它设置

由于自动生成的字段是编码,可以使用数据字典将其转为对应的部门名称,如下图:


3.3 保存与预览

保存模板,点击分页预览,效果如图一

4FineReport示例二横向组织树

按照下图所示将对应的数据列拖入到单元格中,在右侧单元格属性表-扩展属性中将B1、C1单元格的扩展方向设为横向,

并将B1单元格的左父格设置为A1,C1单元格的左父格设置为B1:


 

4.1 条件属性

有上面预览数据可以看到从二层FR_GEN_1开始,就会有空白数据,这是因为数据库中存储的数据有上一级部门本身的部门名称和部门ID,其上一级部门的部门级数会低一级,比如说上述数据的第一列为总部,虽然总部下面有子部门,但是数据库中还是要存储总部这个部门的部门名称和部门ID的,总部对应的级数为一级,那么其对应的数据记录列里面就只有FR_GEN_0层,下面的FR_GEN_1和FR_GEN_2这两层就会没有数据,显示为空白。

在模板制作过程中,从第二层级开始就会有空白数据,需要将空白数据隐藏掉,选中B1和C1单元格,添加条件属性,当数据为空时隐藏该列,如下图:


4.2 其它设置

由于自动生成的字段是编码,可以使用数据字典将其转为对应的部门名称,如下图:


4.3 保存与预览

保存模板,点击分页预览,效果如图二。

5.FineReport示例三存储过程创建树数据集

5.1问题描述

存储过程直接生成树数据集无效,如图:


5.2解决思路

先建立数据库查询数据集ds1,然后数据集ds1里 “call 存储过程名 存储过程参数”,再用ds1生成树数据集 。

若是调用数据库存储过程取数,官方只支持查询语句select进行取数,其他写法(例如下面的写法), 返回的结果不能保证,不建议使用 :

具体操作步骤如下:

新建一个数据库查询,输入:{call username.package.procedure('${p1}','${p2}','${p3}',?)},然后设置下参数的初值,这样就产生了一个普通的数据集ds1,如图:


再通过数据集ds1,设置树数据集就好了,此时就可以正常生成树数据集了,如图:


其余操作和本文描述一样了,只不过是通过存储过程实现组织树报表,需要增加调用存储过程这步。

本文首发于CSDN:http://blog.csdn.net/szd_happy/article/details/72865899

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326356263&siteId=291194637