从ssrs导出后,在excel中冻结列标题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从ssrs导出后,在excel中冻结列标题相关的知识,希望对你有一定的参考价值。

我创建了一个报告,现在我需要冻结tablix标题。我尝试了与SSRS中的冻结窗格相关的所有方法,但是在导出到excel之后,冻结窗格无法正常工作。您知道在SSRS 2016中实现这一目标的任何方法吗?

以下是我尝试过的步骤:

  1. 选择tabix并单击Tablix属性。
  2. 在“列标题”部分下的“常规”选项卡中,您可以看到“滚动时保持标题可见”复选框,然后选中它。
  3. 现在标题行将在报告中保持固定。

要么

  1. 在分组窗格中,确保打开高级模式(单击分组窗格最右侧的小黑色向下箭头)
  2. 在行组层次结构中选择相应的(静态)项
  3. 在属性网格中,将RepeatOnNewPage设置为true
  4. KeepwithGroup to After

要么

  1. 冻结所有列的标题[冻结表标题]:从行组[高级模式]中选择表标题行的静态成员并将FixedData设置为true
  2. 冻结最初的2列:要在列组中选择列的静态成员,并将fixedData设置为true。
答案

我知道这个问题有两种不同的解决方案。每个都有其优点和缺点。

解决方案1

您可以在mssqltips.com上关注本指南。此解决方案允许您为每列创建一个文本框,并将其放在报表标题中。完成工作是一种繁琐而繁琐的方式,但它有效并且全部都包含在报告中。

解决方案2

实现这一目标的第二种方法是使用PowerShell。只有在您可以安排报告的分发而不是在SSRS门户中进行按需访问时,此解决方案才有效。您有PowerShell生成报告,修改输出和分发。以下是PowerShell脚本示例。

#Set variables
$ReportServerUri = "http://MySsrsServer/ReportServer_MySsrsServer/ReportExecution2005.asmx?WSDL"
$ReportPath = "/MyReportPath"
$ReportOutputType = "EXCEL"
$ReportOutputDirectory = "C:SsrsOutput"
$ReportOutputFileName = "MyReport.xlsx"
$ReportOutput = $ReportOutputDirectory + $ReportOutputFileName

#Connect to web service
$ReportServer = New-WebServiceProxy -Class 'ReportServer' -Namespace 'ReportServer' -Uri $ReportServerUri -UseDefaultCredential
$ReportServer.Url = $ReportServerUri

#Load report
$Report = $ReportServer.GetType().GetMethod("LoadReport").Invoke($ReportServer, @($ReportPath, $null))

#Other variables to hold parameters and output values
$parameters = @()
$deviceInfo = "<DeviceInfo><NoHeader>True</NoHeader></DeviceInfo>"
$extension = ""
$mimeType = ""
$encoding = ""
$warnings = $null
$streamIDs = $null

#Render the report
$RenderOutput = $ReportServer.Render($ReportOutputType,
    $deviceInfo,
    [ref] $extension,
    [ref] $mimeType,
    [ref] $encoding,
    [ref] $warnings,
    [ref] $streamIDs
)

#Write file
$Stream = New-Object System.IO.FileStream($ReportOutput), Create, Write
$Stream.Write($RenderOutput, 0, $RenderOutput.Length)
$Stream.Close()

#Open Excel
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
$excel.DisplayAlerts = $False

#Open File
$workbook = $excel.Workbooks.Open($ReportOutput)

#Disable Split
$excel.ActiveWindow.Split = $false

#Freeze Panes
$excel.Rows.Item("10:10").Select() | Out-Null
$excel.ActiveWindow.FreezePanes = $true

#Save and Close Workbook
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlWorkbookDefault
$workbook.SaveAs($ReportOutput, $xlFixedFormat)
$workbook.Close($true)

#Close Excel
$excel.Quit()

#Send out email
Send-MailMessage -From "MySsrsReports@MyOrg.com" -To "ReportUsers@MyOrg.com" -Subject "My Report" -SmtpServer "email.myorg.com" -Attachments $ReportOutput

以上是关于从ssrs导出后,在excel中冻结列标题的主要内容,如果未能解决你的问题,请参考以下文章

在SSRS报告中冻结专栏

将报表表单SSRS导出到Excel仅将小数添加到0.00值

ssrs报告导出到excel - 损坏的超链接

Excel VBA代码将SSRS数据作为数据集提取

如何在SSRS中将报告导出到.CSV?

从 s-s-rS 导出到 Excel 中删除附加列