ssrs行高_SSRS中的备用行颜色

ssrs行高

Setting alternate row colors in SSRS (SQL Server Reporting Services) is an important visualization configuration for end-users so that they can easily view their reports. However, setting alternate colors in SSRS is not a click of a button configuration like in the Microsoft Excel.

在SSRS(SQL Server Reporting Services)中设置备用行颜色是最终用户的重要可视化配置,以便他们可以轻松查看其报告。 但是,在SSRS中设置替代颜色并不是像Microsoft Excel中那样单击按钮配置。

The following screenshot shows the output in Microsoft Excel when the Alternate row color is set for a table.

以下屏幕快照显示了为表设置“备用行”颜色时Microsoft Excel的输出。

How alternate Row colors are set in Microsoft Excel.

However, in SSRS this is not straight forward as in Microsoft Excel shown in the above screenshot.

但是,在SSRS中,这并不像上面的屏幕快照中所示的Microsoft Excel那样直接。

Let us configure a report in SSRS.

让我们在SSRS中配置报告。

SSRS样本报告 (SSRS Sample Report)

Following is the SSRS project solution.

以下是SSRS项目解决方案。

SSRS Project Solution to demostrate alternate row colors.

First, the data source is created for the AdventureWorks sample database in any SQL Server instance. After the data source creation, the next step is to create a data set with the following t-SQL code.

首先,在任何SQL Server实例中为AdventureWorks示例数据库创建数据源。 创建数据源之后,下一步就是使用以下t-SQL代码创建数据集。

SELECT SO.SalesOrderID
  ,SO.RevisionNumber
  ,SO.OrderDate
  ,P.NAME AS ProductName
  ,SOD.OrderQty
  ,SOD.UnitPrice
  ,SOD.LineTotal
FROM Sales.SalesOrderDetail AS SOD
INNER JOIN Sales.SalesOrderHeader AS SO ON SOD.SalesOrderID = SO.SalesOrderID
INNER JOIN Production.Product AS P ON SOD.ProductID = P.ProductID
WHERE SOD.SalesOrderID IN (
    43660
    ,43663
    ,43666
    ,43672
    ,43682
    ,43685
    )
ORDER BY SO.SalesOrderID

Please note that only six orders are used for demonstration purposes. Also, the data set is sorted by the order by OrderID for the demonstration purposes.

请注意,仅六个订单用于演示目的。 同样,出于演示目的,数据集按OrderID和OrderID排序。

Next is to create a table in the SSRS report and link with the data set and you will see the following report.

接下来是在SSRS报告中创建一个表并与数据集链接,您将看到以下报告。

Defaut SSRS report

No major formatting was done to the report except for the rounding the Line total to the two decimal points.

除了将“行总计”四舍五入到小数点后两位以外,没有对报告进行任何主要格式设置。

表的SSRS中的备用行颜色 (Alternate Row Colors in SSRS for Table)

The next task is to set alternate row colors in SSRS in the above SSRS Report.

下一个任务是在上述SSRS报告中的SSRS中设置备用行颜色。

Right-click the data row as shown in the below screenshot, click F4 or properties window in the View menu.

右键单击数据行,如下面的屏幕快照所示,在视图菜单中单击F4或属性窗口。

Configuring alternate row colors in SSRS Report.

When selecting this, you will see the BackgroundColor option. By default, it is No Color, which means that there is no color for the background and use can select any colors. However, those options will provide a report with the same colors for all rows, not for alternate row colors in SSRS Report as required.

选择此项时,您将看到BackgroundColor选项。 默认情况下,它是No Color ,这意味着背景没有颜色,用户可以选择任何颜色。 但是,这些选项将为所有行提供具有相同颜色的报告,而不是根据需要为SSRS报告中的替代行颜色提供报告。

You can select the Expression… option in the listed options which will give you a screen when you can enter an expression.

您可以在列出的选项中选择“ 表达式...”选项,当您输入表达式时,将显示一个屏幕。

Expression for the alternate row colors in SSRS.

In the expression, ROWNUMBER function is used. ROWNUMBER will be the row number for the row. The method used in this case is that the odd row numbers are light blue while the even row numbers are blue. Odd rows are found by for the rows which has reminder 1 when the row number is divided by 2 and similarly, the even rows are the rows which will be the reminder 0 when the row number is divided by 2. This entire logic is used with the IIF and ROWNUMBER functions as shown in the above screenshot.

在表达式中,使用了ROWNUMBER函数。 ROWNUMBER将是该行的行号。 在这种情况下使用的方法是奇数行号为浅蓝色,而偶数行号为蓝色。 对于行号除以2时具有提醒1的行,可以找到奇数行,类似地,偶数行是当行号除以2时将成为提醒0的行。 IIF和ROWNUMBER的功能如上面的屏幕截图所示。

Then the SSRS report is shown as following which has alternate row colors.

然后,SSRS报告如下所示,具有备用行颜色。

Final output of alternate row colors in SSRS

Now this will be same as what you get in Microsoft Excel.

现在,这将与您在Microsoft Excel中获得的内容相同。

分组时SSRS中的备用行颜色 (Alternate Row Colors in SSRS When Grouping)

In SSRS, typically you add groups to the detail records. For example, in the above report, the Sales Order ID is repeated in the above data set. This means that the report can be grouped by the Sales Order ID and when the grouping is done, the report will be looked like the following screenshot.

在SSRS中,通常将组添加到详细记录。 例如,在以上报告中,在以上数据集中重复了销售订单ID。 这意味着可以按销售订单ID对报告进行分组,完成分组后,该报告将看起来像以下屏幕截图。

Invalid alternate row color in SSRS when the grouping is done for the tablix report.

You will observe that background color has gone wrong for the grouping rows. This is because an additional row is introduced to the grouping column. To avoid this, the background color of the grouping row should be modified accordingly.

您会发现分组行的背景色出了问题。 这是因为在分组列中引入了另一行。 为避免这种情况,应相应地修改分组行的背景色。

Modify back ground for color in the grouped report.

Then the report will look like the following screenshot.

然后该报告将类似于以下屏幕截图。

Alternate row colors in SSRS for the grouping in SSRS reports.

SSRS矩阵控件中的备用行颜色 (Alternate Row Colors in SSRS Matrix Control)

Matrix is an SSRS control from which you can have dynamic columns and rows. This means that unlike in the previous example of tables, in the matrix control, columns will grow.

Matrix是一个SSRS控件,您可以从中获得动态的列和行。 这意味着与前面的表示例不同,在矩阵控件中,列将增加。

In the following report, order numbers are in the columns while the product names are in the rows. In case you get a new order number that will appear in the next column.

在以下报告中,订单号在列中,而产品名称在行中。 如果您获得一个新的订单号,该号码将出现在下一列中。

Sample Matrix report is SSRS.

Due to this dynamic nature of the report, the previous simple rule will not work for matrix. If you apply the same rule, the alternate color will occur not at the row level but for every value in the matrix.

由于报告具有这种动态性质,因此以前的简单规则不适用于矩阵。 如果您应用相同的规则,则替代色将不会出现在行级别,而是会出现在矩阵中的每个值上。

This means we need a new approach for the reports with matrix control.

这意味着我们需要采用矩阵控制的报告的新方法。

  1. Add a column outside the dynamic columns which are shown in the following screenshot and highlighted column is the newly added column

    Add a column outside the dynamic columns

    在动态列之外添加一列,如以下屏幕截图所示,突出显示的列是新添加的列

  2. Then add an expression to the newly added column as shown in the below screenshot. This column is Textbox10

    Adding a value to the newly added column.

    Expression is : =IIF(RUNNINGVALUE (Fields!ProductName.Value,CountDistinct,Nothing) Mod 2, “LightBlue”, “Blue”)

    It is similar to the previous expression, but only thing is, RUNNINGVALUE for the grouped column which is the Product Name is used.

    Now you will get the color into the text value as shown in the below screenshot:

    然后将表达式添加到新添加的列,如下面的屏幕快照所示。 此列是Textbox10

    将值添加到新添加的列。

    表达式为: = IIF(RUNNINGVALUE(Fields!ProductName.Value,CountDistinct,Nothing)Mod 2,“ LightBlue”,“ Blue”)

    它与先前的表达式相似,但唯一的区别是,使用了分组列(即产品名称)的RUNNINGVALUE。

    现在,您将把颜色变成文本值,如下面的屏幕截图所示:

  3. Next step is to get the background color from the value of the newly added column. Since the color is available the newly added column, that color can be set to the background of the matrix row

    Seeting up value of the nwely column to the background color of the row.

    下一步是从新添加的列的值中获取背景色。 由于颜色是新添加的列可用,因此可以将该颜色设置为矩阵行的背景

  4. Next is to hide the newly added column since this column is used only as an internal column to the report. This can be done by setting the Hidden option to True

    Hide the newly added column

    下一步是隐藏新添加的列,因为此列仅用作报表的内部列。 可以通过将“ 隐藏”选项设置为“ True”来完成

Finally, the report will look like the following screenshot.

最后,该报告将类似于以下屏幕截图。

Final output for alternate row colors in SSRS Matrix control.

In both the modes, a new the column is added, and it will automatically get the necessary background color so that it does not need any additional configurations. Also, instead of the name of the color, you can use the color code which can be taken from the RGB Color Codes Chart

在这两种模式下,都会添加新的列,并且该列将自动获得必要的背景色,因此不需要任何其他配置。 另外,您可以使用可以从RGB颜色代码表中获取的颜色代码来代替颜色名称。

翻译自: https://www.sqlshack.com/alternate-row-colors-in-ssrs/

ssrs行高

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值