这是我所知道的:
- 我知道文档图和书签可以在屏幕上使用,但不能在 pdf 中使用。
- SSRS 不具备将带页码的打印目录生成 pdf 的开箱即用功能。
- 我知道可以通过将文档结构图导出到Word来生成TOC。这种方法不适用于我的情况。
- 全局变量可以存储页码,但不能在报表正文中使用,只能在页眉和页脚中使用。
我能找到的最接近的东西是创建外部程序集或 dll 使其工作的参考。这个链接埃里克·查兰的博客说可以做到,但没有发布任何代码。如果有人能给我该方法的代码,我也许能够一瘸一拐地复制 .net 程序集,但我从未创建过该方法,而且我对 VB 的了解非常有限,而且没有 C# 知识。我只引用过 SSRS 中的 dll。
根据搜索此解决方案的人数,任何编写此外部程序集的人都将帮助很多人!我知道我会非常感激。
预先感谢您的关注。
这是我在同事和同事的帮助下能够做到的。效果很好。
- 创建主报告,其中目录中列出的每个部分有 1 个子报告
-
创建此表来保存 dll 所需的数据。
CREATE TABLE [dbo].[tbl_TOC](
[RID] [int] IDENTITY(1,1) NOT NULL,
[TOCExecutionID] [varchar](50) NULL,
[AssessmentID] [int] NULL,
[ReportName] [varchar](50) NULL,
[GlobalsTotalPages] [int] NULL,
[LoadDate] [datetime] NULL DEFAULT (getdate())
) ON [PRIMARY]
-
创建此存储过程以添加必要的数据。我们从运行报告的界面发送了一个唯一的 ID。我们还使用了报告特有的另一个参数 (AssessmentID)。
create proc rpt_dsTOC
@TOCExecutionID varchar(50)
as
if OBJECT_ID('tempdb..#temp') is not null drop table #temp
create table #temp (
ord int NOT NULL,
ReportName varchar(50) NULL,
PageCnt int NULL,
PageNo int null )
;with ctePageCount as (
select distinct t.ReportName
, t.GlobalsTotalPages PageCnt
, t.TOCExecutionID
, t.AssessmentID
from tbl_TOC t
where TOCExecutionID=@TOCExecutionID
)
insert into #temp
select case when ReportName like 'Plan%' then 1 --List all of the names of the subreports here
when ReportName like 'Busin%' then 2
when ReportName like 'Threa%' then 3
when ReportName like '%Manag%' then 4
when ReportName like '%Monit%' then 5
when ReportName like 'Pande%' then 6
when ReportName like 'Emerg%' then 7
when ReportName like 'Key%' then 8
when Reportname like 'Netw%' then 9
else 10 end ord
, ReportName
, PageCnt
, 0 PageNo
from ctePageCount
--This section calculates the pagenumber by using the total number of pages in each section
declare @run int = 3
declare @ord int, @ReportName varchar(50), @PageCnt int, @PageNo int
declare c cursor for
select ord
, ReportName
, PageCnt
, PageNo
from #temp
order by ord;
open c
fetch next from c into @ord, @ReportName, @PageCnt, @PageNo
update #temp set PageNo=@run
set @run = @run + @PageCnt--5
while @@FETCH_STATUS = 0 --EOF
begin
fetch next from c into @ord, @ReportName, @PageCnt, @PageNo
if @PageNo=0
set @PageNo = @run
update #temp set PageNo=@PageNo where ord=@ord
set @run = @PageNo + @PageCnt
end
close c
deallocate c
select * from #temp order by ord
该存储过程成为主报告中目录的数据集。
- 放置引用数据集的目录表。
-
创建 dll ReportTOC.ClassTOC:
using System;
using System.Data;
using System.Data.SqlClient;
namespace ReportTOC
{
public class ClassTOC
{
public static string logReportAttributes(string TOCExecutionID, int AssessmentID, string ReportName, int GlobalsTotalPages)
{
string retValue = String.Empty;
try
{
// long TOCExecutionID = long.Parse(DateTime.Now.ToString("yyyyMMddHHmmss"));
using (var conn = new SqlConnection("Server=10.2.36.11;Database=InternalApps;User Id=webclient;Password=webclient;MultipleActiveResultSets=true"))
using (var command = new SqlCommand("usp_LogReportAttributes", conn) { CommandType = CommandType.StoredProcedure })
{
conn.Open();
command.Parameters.AddWithValue("@TOCExecutionID", TOCExecutionID);
command.Parameters.AddWithValue("@AssessmentID", AssessmentID);
command.Parameters.AddWithValue("@ReportName", ReportName);
command.Parameters.AddWithValue("@GlobalsTotalPages", GlobalsTotalPages);
command.ExecuteNonQuery();
}
retValue = "Sent Successfully";
}
catch (Exception ex)
{
retValue = string.Format("{0} \n\r {1}", ex.Message != null ? ex.Message : "", ex.InnerException != null ? ex.InnerException.Message : "");
}
return retValue;
}
}
}
我们使用.NET Framework 3.5
- 在每个子报告中:
设置对程序集的引用:
ReportTOC,版本 1.0.0.0,文化=中性,PublicKeyToken=null
- 将 dll 保存在本地(开发人员)计算机上:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies
- 将 dll 保存在您的报表服务器上:
C:\Program Files\Microsoft SQL Server\MSRS11.MSSQLSERVER\Reporting Services\ReportServer\bin\ReportTOC.dll
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)