问题描述
我有许多SSRS报告正在打印到专用的Zebra标签打印机,其中打印机是用户的默认打印机.每个报告都传递一个参数:Number_Of_Copies.在调用此功能的应用程序中,作为Number_Of_Copies的值,可以有1到任意数量的副本.我不知何故需要制作一份报告,但要指出有很多副本(之间有分页符),并有一个字段指示标签为:"x of Number_Of_copies".这显然说起来容易做起来难. SSRS报告本身(通过命令行调用)中是否有办法做到这一点?
I have a number of SSRS Reports that are printing to dedicated Zebra Label printers where the printer is the default for the user. Each report is passed a parameter: Number_Of_Copies. In the application that calls this there can be 1 to any number of copies as a value for Number_Of_Copies. Somehow I need to product a report with however many copies are indicated (with page breaks between) and a field that indicates which sequence number the label is: "x of Number_Of_copies." This is apparently easier said than done. Is there a way in the SSRS Report itself (which is being called via a command line) to do this?
推荐答案
这是您的操作方法...
Here's how you can do it...
哦,这很罗word,但实际上很简单.
Oh, and this is quite wordy but it's actually very simple..
我们首先需要的是您的标签报告,我想您已经知道了,因此我将其称为LabelA
.我们需要编辑此报告,以便它接受2个参数(Copies
和CurrentCopy
).添加带有适当表达式的文本字段以显示此信息,例如
First thing we need is your label report, which I assume you've got and I'll call it LabelA
for the purpose of this answer.We need to edit this report so that it accepts 2 parameters (Copies
and CurrentCopy
). Add a text field with an appropriate expression to display this info e.g.
="Label " & Parameters!CurrentCopy.Value & " of " & Parameters!Copies.Value
运行此报告并通过手动输入两个参数的数字来测试其是否有效.知道这可以正常进行后,请继续.
Run this report and test it works by typing in numbers for the two parameters by hand. Once you know this is working OK, proceed.
接下来,我们需要另一个报告,它将作为我们的循环,所以....创建一个新报告,我们称之为LabelA_Loop
(我知道名字很糟糕!)
Next we need another report which will act as our loop, so....Create a new report, let's called it LabelA_Loop
(I know terrible name!)
在LabelA_Loop
中,创建数据集并将其命名为dsLoop
将数据集的查询设置为类似以下内容.
In LabelA_Loop
, create dataset and call it dsLoop
Set the query for the dataset to something like this..
DECLARE @counter int = 1
DECLARE @t TABLE (RowNum int)
WHILE @Copies >= @counter
BEGIN
INSERT INTO @t SELECT @counter
SET @counter = @counter +1
END
SELECT * FROM @t ORDER BY rownum
(当然,您甚至可以使用任何东西来创建数字列表,即使有一个大数字表,但这也很容易,而且容易实现...)
此时,将根据您的dsLoop
数据集的需要自动创建参数(@Copies
).
At this point, a parameter (@Copies
) will have been created automatically as it's required by your dsLoop
dataset.
下一步,将表添加到报告中.接下来,将tablix(我们刚刚添加的表)的数据集属性设置为dsLoop
该表只需要一列宽,而没有标题行,因此从本质上讲,我们将只剩下一个单元格".删除行标题和最后两列,直到只剩下一个单元格.
Next step, add a table to the report.Next, set the dataset property for the tablix (the table we just added) to be dsLoop
The table will only need to be one column wide and no header row so essentially we'll be left with a single 'cell'. Delete the row header and last two columns until you only have a single cell left.
在表格单元格中,插入一个子报表,并将subreport property
设置为我们的标签报表LabelA
.在子报表的参数中,将Copies
设置为Copies
参数,将CurrentCopy
设置为dsLoop
数据集中的RowNum
字段.
In the table cell, insert a subreport and set the subreport property
to be our label report LabelA
.In the parameters for the subreport, set Copies
to be your Copies
parameter and set CurrentCopy
to be the RowNum
field from your dsLoop
dataset.
您需要调整单元格的大小以适合和设置分页符,仅此而已.循环报告采用参数Copies
,数据集使用该参数生成正确数量的记录.它将在数据集中为每条记录添加一行,每行将包含一个标签子报表,并且每个子报表将传递两个参数,即当前副本和总副本,这些参数又呈现在最终标签中.
You'll need to resize the cell to suit and set page breaks but that's it. The loop report takes a parameter Copies
which the dataset uses to generate the correct number of records. It will add one row per record in the dataset, each row will contain a label subreport and each subreport will be passed two parameters, the current copy and the total copies, which in turn are rendered in the final label.
这篇关于SSRS中需要代码来创建报告的多个序列化副本(标签)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!