[转]Creating Mailing Labels in SQL Server Reporting Services (rdlc 数据1页 2竖排 显示)
本文转自:http://blogs.wrox.com/article/creating-mailing-labels-in-sql-server-reporting-services/
Most word processing applications (Word, WordPerfect, and so on) provide the capability to create a “mail merge” from which to generate mailing labels in different formats and layouts. Mailing labels are an automated way to generate the address labels for a large number of envelopes or parcels that need to be mailed.
Reporting Services provides a few features that allow you to create mailing labels in different formats – the only thing you need to know are the exact dimensions of the label template you are targeting when printing. A common mailing label format is to use multiple columns (newspaper layout) in order to maximize the number of labels printed.
This recipe shows you how to leverage Reporting Services’ multi-column layout features to create basic mailing labels, while explaining certain limitations in the rendering engine.
Product Versions
All versions (examples provided in Reporting Services 2008)
What You’ll Need
AdventureWorksDW2008 database (or your own database and query that provides name and address data to the report)
The exact template size for the labels you will use when printing (including all margins and column widths)
A PDF reader or Image viewer (Windows provides an image viewer that supports TIFF, JPG, GIF, and PNG)
Designing the Report
The final outcome of this recipe should be a multi-column report “perfectly” sized to fit the print layout of a mailing label template, as shown in Figure P6-7.
Figure 6-7
For the purposes of this recipe, you will utilize the Avery 5160 label template, which contains the following dimensions:
Length: 2.5935”
Height: 1.0000”
Margins: Top 0.5”, Bottom 0.5”, Left 0.21975”, Right 0.21975”
Horizontal Spacing (gutter): 0.14000”
Vertical Spacing (gutter): 0”
30 labels per sheet of letter size (8.5” x 11”) paper
1. Begin by creating a new report in Report Builder, and removing all default items and the page footer from the report. You need to have a blank design surface – the report dimensions need to be very exact in order to match the labels when printing.
2. Add a new data source to the report and set its connection string to the SQL Server where the AdventureWorksDW2008 database is stored. If you are using your own database, simply choose the server and database for your own data, so you can provide your own query in the next step.
3. Add a new dataset for the data source created in the previous step. Set the query type to Text, and type the following SQL query in the command text window:
SELECT
c.Title, c.FirstName, c.MiddleName, c.LastName
, c.AddressLine1, c.AddressLine2
, g.City, g.StateProvinceCode, g.PostalCode
, g.EnglishCountryRegionName
FROM
dbo.DimCustomer c
LEFT OUTER JOIN
dbo.DimGeography g
ON g.GeographyKey = c.GeographyKey
WHERE
g.EnglishCountryRegionName = @Country
ORDER BY
g.StateProvinceCode
, g.City
, c.LastName
Notice that this includes a parameter for the Country field—this will allow you to filter down the dataset to a specific country. Also, you order by State/Province, then by City, and finally, by Last Name. That seems like a reasonable way to order your labels and keep your mail person happy when processing a large case of envelopes or parcels. You should have a blank report with a dataset as shown in Figure P6-8.
Figure P6-8
4. The label template will contain three columns on a letter-size sheet of paper, so you need to set up the report size and layout for multiple columns:
a. In the Report Properties, set the Orientation to Portrait, and Paper Size to Letter (8.5in x 11in).
b. Set the Left and Right Margins to 0.21975in
c. Set the Top and Bottom Margins to 0.5in
Click the OK button to save changes. The report properties should look as shown in Figure P6-9.
Figure P6-9
5. Next, you need to set up multiple columns. The Columns and ColumnSpacing properties of the Report are not exposed via the Report Properties dialog shown in Figure P6-9. Instead, you must edit them in the Properties page for the report (if you don’t see it in Report Builder, choose the View menu from the ribbon and check the Properties box to display it).
Expand the Columns node from the Properties page, and make the following edits (see Figure P6-10):
a. Change the Columns property to 3
b. Change the ColumnSpacing property to 0.14in. This is the size of our label template’s Horizontal Spacing gutter – the spacing between columns on the page.
Figure P6-10
Notice that the report body has been “duplicated” by the number of columns specified in the Columns property, even though you only get to work on the leftmost body template (the other ones are simply placeholders to show the designer that multiple columns will be rendered at runtime).
Since you already specified the dimensions for your label template, you might be wondering why the report is so wide, making you scroll to the right to see the multiple columns. There still are a few dimensions that you must set for the body of the report.
It’s important to understand how report page sizes, body sizes, margins and column spacing relate to each other in the report. Figure P6-11 illustrates how these dimensions fit together.
Figure 6-11
From the diagram, you can then infer that the labels themselves will be the body, while the sheet of paper will be the report page. With that in mind you will set the body dimensions according to the label size specified previously.
6. Click on the Body element, and change the following properties in the Properties window:
a. Expand the Size node and set the Width to 2.5935in
b. Set the Height to 1in
Your report body should now look like the diagram in Figure P6-12.
Figure P6-12
7. Finally, you add a data region to the body of the report, attach it to your dataset and drag data fields in for the mailing data.
In Reporting Services 2008, you can use either a List or a Table data region (both use the underlying tablix). However, if you are using an earlier version, I have found the table layout to yield more consistent results and provide a better design surface to control your formatting. I’ll let you, as the report developer, decide what best fits your needs according to the requirements of your mailing label design.
I’ll simply use a table with a single column and detail row, and rely on the Reporting Services 2008 rich text features of the textbox that allow you to drag and drop multiple dataset fields onto the table cell. Make sure your data region (table or list) stretches to fill 100% of the body size, without expanding it. In other words, the width and height of the data region should match that of the body. The easiest way to do this is by drawing the data region on the design surface instead of dragging it from the menu. After adding the data region to the report, double-check that your report body was not modified by the data region.
If you are using a previous version of Reporting Services, you will either use string concatenation expressions (not recommended) or use a rectangle in the cell to make the cell a free-form container for your textboxes – then you can use multiple textboxes for the dataset field, each positioned absolutely within the cell.
Here’s a trick to ensure that your labels are positioned correctly within the cell: select the cell textbox and set its vertical alignment to “Middle”. For some reason, Reporting Services will duplicate the data cell otherwise.
Assuming your mailing labels will require First and Last Name, Address 1 and 2, City, State, Postal Code, and Country name to be displayed, the table cell layout should look similar to Figure P6-13.
Figure P6-13
While previewing the report, keep in mind that the report viewer used in the preview of the report designer uses the Graphics Device Interface (GDI) to render the report to the screen, and because we are using multi-columns, a feature only supported in the print-oriented renderers for Reporting Services, you will only get to see the expected outcome if you click the “Print Layout” button in the preview window. This leverages the print-preview renderer and not the regular preview renderer. Also, because of this limitation, a multi-column report layout is only supported in print-oriented formats: PDF, TIFF (Image), Print, and Print Preview. You cannot export and save your report to Word, so your best option is to use PDF.
The final outcome of the report in Print Layout preview is shown in Figure P6-14 (I added light gray borders to my textbox, so you can see the size of the labels).
Figure P6-14
Final Thoughts
Reporting Services provides developers with several features to help create insightful analytical reports, as well as print-ready reports. With its multicolumn capabilities, we are able to drastically change the layout of reports that target a print layout such as PDF.
This recipe showed you how to leverage the multicolumn feature to create mailing labels akin to those found in Microsoft Word’s mail merge feature. The compelling story, however, lies within the integration and automation possibilities. As most developers would agree, Office automation is rather complex and can be a bit frustrating at times. However, with Reporting Services’ web services API, its extensibility, and rich subscription model, the task of automating the creation of mailing labels becomes much simpler.
Credits and Related References
Mailing label dimensions provided by Worldlabel.Com, Inc. (www.worldlabel.com).
This article is excerpted from Part VI: "Enhanced Report Content" of the book "Microsoft SQL Server Reporting Services Recipes: for Designing Expert Reports" by Paul Turley, Robert M. Bruckner (ISBN: 978-0-470-56311-3, Wrox, 2010, Copyright Wiley Publishing Inc.)
[转]Creating Mailing Labels in SQL Server Reporting Services (rdlc 数据1页 2竖排 显示)的更多相关文章
- Integrating .NET Code and SQL Server Reporting Services
SQL Server Reporting Services versions 2000 and 2005 (SSRS) has many powerful features. SSRS has a w ...
- SQL Server Reporting Services本机模式下的权限管理
SQL Server Reporting Services在安装配置后,缺省只给BUILTIN\Administrators用户组(实际上只有本机的Administrator用户)提供管理权限.所以所 ...
- SrsDataConnector The SQL Server Reporting Services account is a local user and is not supported.
这次使用OS+SQL的镜像还原系统后安装了CRM 2015,主要流程是 安装IIS/AD,SSRS ,CRM2015.自带的SQL中SSRS没有安装完全,需配置一下. 这一切都满顺利的,最后在安装 S ...
- 充分利用 SQL Server Reporting Services 图表
最近在查SSRS的一些文章,看到MSDN在有一篇不错的文章,许多图表设置都有说明,共享给大家.. 其中有说明在SSRS中如果去写条件表达写和报表属性中的“自定义代码”,文章相对比较长,需要大家耐心的查 ...
- SQL Server Reporting Services – Insufficient Rights Error
http://www.sql-server-performance.com/2011/security-ssrs-reporting-error/ SQL Server Reporting Servi ...
- Incorporating ASP.NET MVC and SQL Server Reporting Services, Part 1
Your ASP.NET MVC application needs reports. What do you do? In this article, I will demonstrate how ...
- SQL Server Reporting Services (SQLEXPRESS) 服务占用80端口
win7, 好多时候,看到system进程占用了80端口,这个是系统进程,不能直接结束.我们不知道这个进程的哪个服务占用了80端口,这里记录其中一个服务"SQL Server Reporti ...
- [转]SQL Server Reporting Services - Timeout Settings
本文转自:https://social.technet.microsoft.com/wiki/contents/articles/23508.sql-server-reporting-services ...
- Microsoft Dynamics CRM 2013 安装 报表服务出现“ SQL Server Reporting Services 帐户是本地用户且不受支持 ”错误的解决方法
安装好CRM 2013 之后,还需要安装报表服务,发现出现:SQL Server Reporting Services 帐户是本地用户且不受支持,具体如下图: 经过分析原来发现是需要用域用户,打开对应 ...
随机推荐
- 【错误信息】springMVC No mapping found for HTTP request with URI
出现这个问题的原因是在web.xml中配置错了:
- Struts2 拦截器配置及使用
在我的项目中有个需求,实现记录用户操作的系统日志,基于这个功能我首先想到的是Struts 的拦截器.配置一个全部Action都会拦截的拦截,写一个公用的服务.每当用户发送请求到Action 就记录相应 ...
- Java笔记(八)
GUI: awt和swing: java.awt:Abstract Window ToolKit(抽象窗口工具包),需要调用本地系统方法实现功能.属于重量级控件. javax.swing:在awt的基 ...
- poj2828 Buy Tickets——倒序处理
题目:http://poj.org/problem?id=2828 这题可以倒序来做,因为越靠后的人实际上优先级越高: 用0和1表示这个位置上是否已经有人,0表示有,1表示没有,这样树状数组维护前缀和 ...
- 蓝桥杯校内选拔赛/POJ 数独(深搜)
Sudoku Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14530 Accepted: 7178 Special ...
- 回味经典——uboot1.1.6 之 第一阶段
转自:http://blog.csdn.net/lizuobin2/article/details/52054293 最近打算移植一个比较新的 uboot 到开发板,回想起来上一次移植 uboot1. ...
- apk重签名的两种方法
因为robotium要求被测应用和测试代码要有一致的签名, 所以需要将apk包重签名. 方法一:通过re-sign.jar来产生debug key的apk(不适用于jdk 7以上) re-sign.j ...
- 1、webpack课程介绍
- Makefile研究(二)—— 完整可移植性模板
转自:http://blog.csdn.net/jundic/article/details/17676461 一直想写一个很全很好移植的Makefile模板,我觉得一个完整makefile 应该包含 ...
- CodeForces Gym 100685I Innovative Business (贪心)
题意:给定一条路的长和宽,然后给你瓷砖的长和宽,你只能横着或者竖着铺,也可以切成片,但是每条边只能对应一条边,问你最少要多少瓷砖. 析:先整块整块的放,然后再考虑剩下部分,剩下的再分成3部分,先横着, ...