包含多个参数值的计划1报告

时间:2015-08-20 09:22:46

标签: sql-server reporting-services ssrs-2008 report ssrs-2008-r2

我在SSRS中有一个报告,其中有一个参数。对于参数中的每种可能性,我需要一个Excel文件。这归结为50个Excel文件。我知道安排报告的唯一方法是转到报告服务主页,转到我的报告,点击管理,点击订阅>新订阅并输入文件名,路径,用户名,密码,日程表,参数,最后按OK。

是否有更快的方法可以做到这一点,还是有一种方法可以让我更快地创建50个报告,比如复制订阅或类似的东西?

2 个答案:

答案 0 :(得分:0)

尝试创建一个ssis包并为参数的所有值运行报告。我见过有人在我以前的公司做过这件事。

数据驱动订阅仅适用于企业版和开发人员版 - 您的版本可能是标准版。

答案 1 :(得分:-1)

您还可以在PowerShell中编写脚本或在C#/ VB中编写应用程序。 Here是在PowerShell中完成的示例。 Here是在C#中完成的示例。使用这些方法之一,您可以按照您认为合适的方式以编程方式呈现报告。您也可以create subscriptions这种方式。

OP的PowerShell解决方案:

# Create a proxy to the SSRS server and give it the namespace of 'RS' to use for
# instantiating objects later.  This class will also be used to create a report
# object.
$reportServerURI = "http://<SERVER>/ReportServer/ReportExecution2005.asmx?WSDL"
$RS = New-WebServiceProxy -Class 'RS' -NameSpace 'RS' -Uri $reportServerURI -UseDefaultCredential
$RS.Url = $reportServerURI

# Set up some variables to hold referenced results from Render
$deviceInfo = "<DeviceInfo><NoHeader>True</NoHeader></DeviceInfo>"
$extension = ""
$mimeType = ""
$encoding = ""
$warnings = $null
$streamIDs = $null

# Next we need to load the report. Since Powershell cannot pass a null string
# (it instead just passes ""), we have to use GetMethod / Invoke to call the
# function that returns the report object.  This will load the report in the
# report server object, as well as create a report object that can be used to
# discover information about the report.  It's not used in this code, but it can
# be used to discover information about what parameters are needed to execute
# the report.
$reportPath = "/PathTo/Report"
$Report = $RS.GetType().GetMethod("LoadReport").Invoke($RS, @($reportPath, $null))

# Report parameters are handled by creating an array of ParameterValue objects.
# $excelInput: either pass in as a parameter and run 50 times, or reset
# this value and run it each time with the updated excel file
$excelInput = "<ExcelFile>"; 
$parameters = @()

$parameters += New-Object RS.ParameterValue
$parameters[0].Name  = "Excel Input File"
$parameters[0].Value = $excelInput

# Add the parameter array to the service.  Note that this returns some
# information about the report that is about to be executed.
$RS.SetExecutionParameters($parameters, "en-us") > $null

# Render the report to a byte array.  The first argument is the report format.
# The formats I've tested are: PDF, XML, CSV, WORD (.doc), EXCEL (.xls),
# IMAGE (.tif), MHTML (.mhtml).
$RenderOutput = $RS.Render('PDF',
    $deviceInfo,
    [ref] $extension,
    [ref] $mimeType,
    [ref] $encoding,
    [ref] $warnings,
    [ref] $streamIDs
)

# Convert array bytes to file and write
$OutputFile = $excelInput + ".pdf"
$Stream = New-Object System.IO.FileStream($OutputFile), Create, Write
$Stream.Write($RenderOutput, 0, $RenderOutput.Length)
$Stream.Close()