本文转自: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竖排 显示)的更多相关文章

  1. 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 ...

  2. SQL Server Reporting Services本机模式下的权限管理

    SQL Server Reporting Services在安装配置后,缺省只给BUILTIN\Administrators用户组(实际上只有本机的Administrator用户)提供管理权限.所以所 ...

  3. 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 ...

  4. 充分利用 SQL Server Reporting Services 图表

    最近在查SSRS的一些文章,看到MSDN在有一篇不错的文章,许多图表设置都有说明,共享给大家.. 其中有说明在SSRS中如果去写条件表达写和报表属性中的“自定义代码”,文章相对比较长,需要大家耐心的查 ...

  5. SQL Server Reporting Services – Insufficient Rights Error

    http://www.sql-server-performance.com/2011/security-ssrs-reporting-error/ SQL Server Reporting Servi ...

  6. 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 ...

  7. SQL Server Reporting Services (SQLEXPRESS) 服务占用80端口

    win7, 好多时候,看到system进程占用了80端口,这个是系统进程,不能直接结束.我们不知道这个进程的哪个服务占用了80端口,这里记录其中一个服务"SQL Server Reporti ...

  8. [转]SQL Server Reporting Services - Timeout Settings

    本文转自:https://social.technet.microsoft.com/wiki/contents/articles/23508.sql-server-reporting-services ...

  9. Microsoft Dynamics CRM 2013 安装 报表服务出现“ SQL Server Reporting Services 帐户是本地用户且不受支持 ”错误的解决方法

    安装好CRM 2013 之后,还需要安装报表服务,发现出现:SQL Server Reporting Services 帐户是本地用户且不受支持,具体如下图: 经过分析原来发现是需要用域用户,打开对应 ...

随机推荐

  1. LC_MESSAGES、语言文件po和mo互相转换

    LANGUAGE, LC_ALL, LC_MESSAGES, LANG zz- -   关于这几个环境变量一般认为它们的作用是用来指定程序用户界面语言而且这几个环境变量的优先级是从左到右依次降低的大概 ...

  2. C++之友元机制(友元函数和友元类)

    一.为什么引入友元机制? 总的来说就是为了让非成员函数即普通函数或其他类可以访问类的私有成员,这确实破坏了类的封装性和数据的隐蔽性,但为什么要这么做呢? (c++ primer:尽管友元被授予从外部访 ...

  3. CF 757E Bash Plays with Functions——积性函数+dp+质因数分解

    题目:http://codeforces.com/contest/757/problem/E f0[n]=2^m,其中m是n的质因子个数(种类数).大概是一种质因数只能放在 d 或 n/d 两者之一. ...

  4. JavaScript-Tool:jquery.vaidate.js

    ylbtech-JavaScript-Tool:jquery.vaidate.js 1.返回顶部 1. 2. 3. 2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 0. https ...

  5. .net网站部署时错误——未能加载文件或程序集(Could not load file or assembly)——的解决

    Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKe ...

  6. K个联通块

    题意: 有一张无重边的无向图, 求有多少个边集,使得删掉边集里的边后,图里恰好有K个联通块. 解法: 考虑dp,$h(i,S)$表示有$i$个联通块,点集为$S$的图的个数,$g(S)$表示点集为S的 ...

  7. 洛谷 - UVA11346 - 概率 Probability - 积分

    要是没学过高等数学的积分怎么办呢?可以求助于自适应辛普森法. 容易发现其实这个图形是对称的,我们只要求第一象限就可以了,第一象限如上图. 由于取点是在面积内等概率的,由高中的几何概型可知,所求概率为: ...

  8. 基于thinkphp5的Excel上传

    涉及知识点: thinkphp5.0: excel上传: mysql建立新表(基本的create语句): mysql ignore(避免重复插入): 主要功能: 通过在视图中上传excel文件,在my ...

  9. Lightoj 1067【逆元模板(求C(N,M))】

    #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ...

  10. ComDom在使用函数CompileAssemblyFromFile时无法找到文件的错误

    public virtual CompilerResults CompileAssemblyFromFile( CompilerParameters options, params string[] ...