如何在SQL Server Reporting Services中最好地显示CheckBox?

时间:2021-07-27 08:16:31

One of the many quirks of Reporting Services we've run across is the complete and utter lack of a CheckBox control or even something remotely similar.

我们遇到的众多报告服务的怪癖之一就是完全缺乏CheckBox控件甚至是远程类似的东西。

We have a form that should appear automatically filled out based on information pulled from a database. We have several bit datatype fields. Printing out "True" or "False" just looks silly, as this is supposed to look like a form that has been auto-filled out, so we want to have a series of checkboxes and labels that are either checked or unchecked.

我们有一个表格应该根据从数据库中提取的信息自动填写。我们有几个位数据类型字段。打印出“True”或“False”只是看起来很傻,因为它应该看起来像是一个自动填写的表单,因此我们希望有一系列复选框和标签可以选中或取消选中。

We are running SSRS 2005 but I'm not aware of SSRS 2008 having added a CheckBox control. Even if it did, we'd need to have an alternative for the time being. The best we've found so far is:

我们正在运行SSRS 2005,但我不知道SSRS 2008添加了CheckBox控件。即使这样,我们也需要暂时替代。到目前为止我们发现的最好的是:

  1. use Wingdings
  2. use images
  3. use text boxes with borders and print a blank/space or a capital X
  4. 使用带边框的文本框并打印空白/空格或大写字母X.

All three approaches require IIF expression shenanigans.

所有这三种方法都需要IIF表达恶作剧。

The Wingdings approach seemed to work acceptably, and was the most aesthetically pleasing except that for whatever reason it didn't always print correctly. More importantly, PDF exports, also for whatever reason, converted all fonts (generally) to Arial and so we got funky letters instead of the Windings dingbats.

Wingdings的方法似乎可以接受,并且是最美观的,除了无论出于什么原因它并不总是正确打印。更重要的是,PDF导出,无论出于何种原因,将所有字体(通常)转换为Arial,因此我们得到了时髦的字母,而不是Windings dingbats。

Images, being a pixel-based raster, don't do so well when printed along side vector stuff like text. Unless handled carefully, they tend to stretch, pixelate, and do other unprofessional looking things.

作为基于像素的光栅的图像在沿文本等侧向矢量打印时效果不佳。除非小心处理,否则它们往往会伸展,像素化,并做其他不专业的事情。

While these methods do work (some with limitations as mentioned above) none of them are particularly elegant.

虽然这些方法确实有效(有些方法如上所述),但它们都不是特别优雅。

Are we missing something obvious? Not so obvious? Does someone at Microsoft have a good reason why such a control was not provided in SSRS 2000, let alone 2 versions and 8 years later? This can't be the first time this issue has come up...

我们是否遗漏了明显的东西不是很明显?微软有人有充分的理由说明SSRS 2000中没有提供这样的控制,更不用说两个版本和8年后了吗?这不是第一次出现这个问题......

7 个解决方案

#1


18  

I, along with others in my shop, have used images, toggling the hidden attribute based on the field value (true or false). We haven't had any problems with blurring or scaling, unless we tried to increase the scale of the image beyond 100% obviously.

我和我店里的其他人一起使用了图像,根据字段值(true或false)切换隐藏属性。我们没有任何模糊或缩放问题,除非我们试图将图像的比例显着增加到100%以上。

Another option I've used is similar to the wingdings idea, but I just use a plain old "X". On our forms at least, it is not uncommon for someone to use an X in a box instead of a check mark, so it looks completely acceptable. Plus, you don't have to worry about strange characters when printing.

我使用的另一个选项类似于wingdings的想法,但我只使用一个普通的旧“X”。至少在我们的表格中,有人在盒子中使用X而不是复选标记并不罕见,因此它看起来完全可以接受。另外,打印时不必担心奇怪的字符。

As for why Microsoft does not include a checkbox control, I can't answer that as I've been wondering the same thing myself for a long time now.

至于微软为什么不包含一个复选框控件,我无法回答这个问题,因为我自己很长时间以来一直想知道同样的事情。

#2


11  

What I have used to display a check box (or ballot box):
1- create textbox (that will become your check box)
2- change font to Arial Unicode MS
3- in the expression window use:
ChrW(&H2611) for a filled-in checkbox
ChrW(&H2610) for an empty checkbox

我用来显示一个复选框(或投票箱):1-创建文本框(将成为您的复选框)2-在表达式窗口中将字体更改为Arial Unicode MS 3-使用:ChrW(&H2611)表示已填写-in复选框ChrW(&H2610)表示一个空复选框

#3


8  

Besides the different methods already presented, as of SQL Server 2008 R2 there's a built-in control that can be used for checkbox-alike functionality: the Indicator!

除了已经提出的不同方法之外,从SQL Server 2008 R2开始,还有一个内置控件,可用于类似复选框的功能:指示器!

Have a look here for details on how to use it: http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/

在这里查看有关如何使用它的详细信息:http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/

To be able to use a field of type bit, you'll have to cast it to int first. This can be done either in the dataset query or by adding a calculated field to the dataset.

为了能够使用bit类型的字段,您必须首先将其强制转换为int。这可以在数据集查询中完成,也可以通过向数据集添加计算字段来完成。

If you want the NULLs to come up as yellow, then you'll need to build the expression that way so it takes that requirement into account as well.

如果你想让NULL变成黄色,那么你需要以这种方式构建表达式,以便它也考虑到这个需求。

Here's a possible expression for a calculated field:

这是计算字段的可能表达式:

=Switch(
    IsNothing(Fields!YourBoolean.Value), 50,
    Fields!YourBoolean.Value = False, 0,
    Fields!YourBoolean.Value = True, 100)

Depending on the meaning of your fields - is False good or bad - you may need to swap the zero and 100.

根据你的字段的含义 - 是假的好还是坏 - 你可能需要交换零和100。

#4


7  

I just wanna share the idea on this blog. SSRS: How to Display Checkbox on Report

我只是想在这个博客上分享这个想法。 SSRS:如何在报告上显示复选框

  1. First create a textbox
  2. 首先创建一个文本框

  3. Then change the font family to Wingdings
  4. 然后将字体系列更改为Wingdings

  5. Insert an expression on the textbox and write this expressions.

    在文本框中插入表达式并编写此表达式。

    =IIF(Fields!Active.Value,chr(254),"o")
    

    Fields!Active.Value could be anything from your query that should return a boolean value 1 or 0.

    Fields!Active.Value可以是您的查询中应该返回布尔值1或0的任何内容。

  6. Then click Preview and see the checkbox ;)

    然后单击预览并看到复选框;)

More styles can be selected on the blog that I shared above.

可以在我上面分享的博客上选择更多样式。

Here is an example of my output 如何在SQL Server Reporting Services中最好地显示CheckBox?

这是我输出的一个例子

#5


2  

You can also use a string calculated field like "[X]" or "[ ]". It's less pretty than the textbox with border but you don't have to put a specific control for the value and you can fill table or matrix with this.

您还可以使用字符串计算字段,如“[X]”或“[]”。它不如带边框的文本框漂亮,但您不必为该值设置特定控件,您可以使用此填充表或矩阵。

At least there is some solution for the checkbox. I'm still looking for full justification for my text (In fact I'm looking for another solution than SSRS know).

至少复选框有一些解决方案。我仍然在为我的文本寻找完整的理由(实际上我正在寻找另一种解决方案,而不是SSRS知道)。

ACCESS 97 could make this kind of thing but not SQL SERVER 2012.

ACCESS 97可以做这种事情,但不是SQL SERVER 2012。

#6


1  

I think there is a bug with SSRS and embedding font characters above 128 (some thing todo with ANSI encoding). Basically you can use 1-128 fine, the rest show up as tall rectangular blocks.

我认为SSRS存在一个错误,并且将字体字符嵌入到128以上(有些东西用ANSI编码)。基本上你可以使用1-128罚款,其余显示为高矩形块。

I like NY's idea of the textbox with a border and an optional X - this sounds simple and effective.

我喜欢纽约的带有边框和可选X的文本框的想法 - 这听起来简单而有效。

#7


0  

Another way to do thisd is go to "Placeholder properties" of TextBox and check Html - Interpret HTML tag as styles

另一种方法是转到TextBox的“占位符属性”并检查Html - 将HTML标记解释为样式

Then in the Value - Expression put this line of code for checked:

然后在Value - Expression中将这行代码放入checked:

="<font face=""Wingdings 2"" color=""green"">" & Chr(81) &"</font>" & "some other text"

Or this code sample for unchecked:

或者此代码示例未选中:

="<font face=""Wingdings 2"" color=""red"">" & Chr(163) &"</font>" & "some other text"

This way you can have checkbox and text in the same textbox.

这样,您可以在同一文本框中包含复选框和文本。

如何在SQL Server Reporting Services中最好地显示CheckBox?

Later edit:

If you are having problem displaying Wingdings 2 on Azure, then use Wingdings.

如果您在Azure上显示Wingdings 2时遇到问题,请使用Wingdings。

Apparently it works.

显然它有效。

="<font face=""Wingdings"" color=""green"">" & Chr(253) &"</font>" & "some other text"

Or this code sample for unchecked:

或者此代码示例未选中:

="<font face=""Wingdings"" color=""red"">" & Chr(168) &"</font>" & "some other text"

#1


18  

I, along with others in my shop, have used images, toggling the hidden attribute based on the field value (true or false). We haven't had any problems with blurring or scaling, unless we tried to increase the scale of the image beyond 100% obviously.

我和我店里的其他人一起使用了图像,根据字段值(true或false)切换隐藏属性。我们没有任何模糊或缩放问题,除非我们试图将图像的比例显着增加到100%以上。

Another option I've used is similar to the wingdings idea, but I just use a plain old "X". On our forms at least, it is not uncommon for someone to use an X in a box instead of a check mark, so it looks completely acceptable. Plus, you don't have to worry about strange characters when printing.

我使用的另一个选项类似于wingdings的想法,但我只使用一个普通的旧“X”。至少在我们的表格中,有人在盒子中使用X而不是复选标记并不罕见,因此它看起来完全可以接受。另外,打印时不必担心奇怪的字符。

As for why Microsoft does not include a checkbox control, I can't answer that as I've been wondering the same thing myself for a long time now.

至于微软为什么不包含一个复选框控件,我无法回答这个问题,因为我自己很长时间以来一直想知道同样的事情。

#2


11  

What I have used to display a check box (or ballot box):
1- create textbox (that will become your check box)
2- change font to Arial Unicode MS
3- in the expression window use:
ChrW(&H2611) for a filled-in checkbox
ChrW(&H2610) for an empty checkbox

我用来显示一个复选框(或投票箱):1-创建文本框(将成为您的复选框)2-在表达式窗口中将字体更改为Arial Unicode MS 3-使用:ChrW(&H2611)表示已填写-in复选框ChrW(&H2610)表示一个空复选框

#3


8  

Besides the different methods already presented, as of SQL Server 2008 R2 there's a built-in control that can be used for checkbox-alike functionality: the Indicator!

除了已经提出的不同方法之外,从SQL Server 2008 R2开始,还有一个内置控件,可用于类似复选框的功能:指示器!

Have a look here for details on how to use it: http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/

在这里查看有关如何使用它的详细信息:http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/

To be able to use a field of type bit, you'll have to cast it to int first. This can be done either in the dataset query or by adding a calculated field to the dataset.

为了能够使用bit类型的字段,您必须首先将其强制转换为int。这可以在数据集查询中完成,也可以通过向数据集添加计算字段来完成。

If you want the NULLs to come up as yellow, then you'll need to build the expression that way so it takes that requirement into account as well.

如果你想让NULL变成黄色,那么你需要以这种方式构建表达式,以便它也考虑到这个需求。

Here's a possible expression for a calculated field:

这是计算字段的可能表达式:

=Switch(
    IsNothing(Fields!YourBoolean.Value), 50,
    Fields!YourBoolean.Value = False, 0,
    Fields!YourBoolean.Value = True, 100)

Depending on the meaning of your fields - is False good or bad - you may need to swap the zero and 100.

根据你的字段的含义 - 是假的好还是坏 - 你可能需要交换零和100。

#4


7  

I just wanna share the idea on this blog. SSRS: How to Display Checkbox on Report

我只是想在这个博客上分享这个想法。 SSRS:如何在报告上显示复选框

  1. First create a textbox
  2. 首先创建一个文本框

  3. Then change the font family to Wingdings
  4. 然后将字体系列更改为Wingdings

  5. Insert an expression on the textbox and write this expressions.

    在文本框中插入表达式并编写此表达式。

    =IIF(Fields!Active.Value,chr(254),"o")
    

    Fields!Active.Value could be anything from your query that should return a boolean value 1 or 0.

    Fields!Active.Value可以是您的查询中应该返回布尔值1或0的任何内容。

  6. Then click Preview and see the checkbox ;)

    然后单击预览并看到复选框;)

More styles can be selected on the blog that I shared above.

可以在我上面分享的博客上选择更多样式。

Here is an example of my output 如何在SQL Server Reporting Services中最好地显示CheckBox?

这是我输出的一个例子

#5


2  

You can also use a string calculated field like "[X]" or "[ ]". It's less pretty than the textbox with border but you don't have to put a specific control for the value and you can fill table or matrix with this.

您还可以使用字符串计算字段,如“[X]”或“[]”。它不如带边框的文本框漂亮,但您不必为该值设置特定控件,您可以使用此填充表或矩阵。

At least there is some solution for the checkbox. I'm still looking for full justification for my text (In fact I'm looking for another solution than SSRS know).

至少复选框有一些解决方案。我仍然在为我的文本寻找完整的理由(实际上我正在寻找另一种解决方案,而不是SSRS知道)。

ACCESS 97 could make this kind of thing but not SQL SERVER 2012.

ACCESS 97可以做这种事情,但不是SQL SERVER 2012。

#6


1  

I think there is a bug with SSRS and embedding font characters above 128 (some thing todo with ANSI encoding). Basically you can use 1-128 fine, the rest show up as tall rectangular blocks.

我认为SSRS存在一个错误,并且将字体字符嵌入到128以上(有些东西用ANSI编码)。基本上你可以使用1-128罚款,其余显示为高矩形块。

I like NY's idea of the textbox with a border and an optional X - this sounds simple and effective.

我喜欢纽约的带有边框和可选X的文本框的想法 - 这听起来简单而有效。

#7


0  

Another way to do thisd is go to "Placeholder properties" of TextBox and check Html - Interpret HTML tag as styles

另一种方法是转到TextBox的“占位符属性”并检查Html - 将HTML标记解释为样式

Then in the Value - Expression put this line of code for checked:

然后在Value - Expression中将这行代码放入checked:

="<font face=""Wingdings 2"" color=""green"">" & Chr(81) &"</font>" & "some other text"

Or this code sample for unchecked:

或者此代码示例未选中:

="<font face=""Wingdings 2"" color=""red"">" & Chr(163) &"</font>" & "some other text"

This way you can have checkbox and text in the same textbox.

这样,您可以在同一文本框中包含复选框和文本。

如何在SQL Server Reporting Services中最好地显示CheckBox?

Later edit:

If you are having problem displaying Wingdings 2 on Azure, then use Wingdings.

如果您在Azure上显示Wingdings 2时遇到问题,请使用Wingdings。

Apparently it works.

显然它有效。

="<font face=""Wingdings"" color=""green"">" & Chr(253) &"</font>" & "some other text"

Or this code sample for unchecked:

或者此代码示例未选中:

="<font face=""Wingdings"" color=""red"">" & Chr(168) &"</font>" & "some other text"