【问题标题】:Schedule 1 Report with multiple parameter values具有多个参数值的附表 1 报告
【发布时间】:2015-08-20 09:22:46
【问题描述】:

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

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

【问题讨论】:

  • 查看数据驱动订阅
  • 我认为您需要一个我们没有的特定版本。我只有“删除”和“新订阅”选项

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


【解决方案1】:

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

数据驱动订阅仅在企业版和开发者版中可用 - 您可以是标准版。

【讨论】:

    【解决方案2】:

    您还可以在 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()
    

    【讨论】:

    • 有没有人有机会验证上面的 power shell 脚本?不同格式的示例会更好吗?
    猜你喜欢
    • 1970-01-01
    • 2013-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多