目录

包含大量列的RDL文件

背景

设置

使用代码


包含大量列的RDL文件

使用自动化无法创建包含大量列的SSRS报告。至少我能够找到。因此,在本文中,我将分享一些编写的代码,这些代码可以使用现有的SQL脚本和列标题为您执行此操作。

背景

仔细查看此脚本。您也可以运行它,因为它所做的只是选择语句并构建一个XML字符串。

请注意,如果XML出现较短,这是由于每行和每列的查询返回字符串限制。要更改此设置,请访问:

查询->查询选项->结果->网格(Grid)

将检索到的最大字符数更改为1165535。

设置

此脚本的运行方式是,它将利用现有表来检索其所有列。如果您没有表,只需将脚本的前1个转储到临时表中。在我的示例中,我使用tmptableforssrsreport作为表名。

基本上,查询将遍历所有列并替换无效字符并生成三个XML文件:

  1. TablixRows
  2. TablixColumns
  3. TablixMembers

然后您将获取这些值并使用SSRS,单击F7选项以将您的RDL文件视为XML。在需要添加的1 tablix中找到这些值,并使用返回的值替换它们。

使用代码

步骤 #1: 使用以下方法将数据转储到临时表TmpTableForSSRSReport中:

select top 1 col, col2, col3 into TmpTableForSSRSReport from whatevertable 
/*
Carefully review this script. You can run it as well since all it does is
selects statements and builds an XML string.
Please note that if the XML is coming out short.
This is due to the query return string limit per row and column.
To change this, go to:Query -> Query options -> Results -> Grid Change maximum characters retrieved to 1165535.Setup: The way this script operates is that it will utilize an existing table
to retrieve all of its columns. If you don't have a table, simply dump top 1
of your script into a temporary table.
In my example, I am using tmptableforssrsreport as the table name.Basically, the query will loop through all of columns and replace invalid
characters and generate 3 XML files:
TablixRows
TablixColumns and
TablixMembersYou are then to take these values and using SSRS, click on the F7 option
to see your rdl file as XML. Find these values within the 1 tablix
where you need this added and replace them using the returned values. */--GB. 2021-05-14 step # 1 Dump your data into a temporary table called TmpTableForSSRSReport using select top 1 col, col2, col3 into TmpTableForSSRSReport from whatevertable
--GB. 2021-05-14 You need the table TmpTableForSSRSReport to exist to build the XML
--GB. 2021-05-14 Also please note that you can control what your table is called. In my example, I am using a table called TmpTableForSSRSReport.declare @TablixHeader nvarchar(max) = ''
declare @TablixDetails nvarchar(max) = ''
--GB. 2021-05-14 step # 2 update below with the name of your table.
declare @TempTableName nvarchar(500) = 'TmpTableForSSRSReport' --GB. 2021-05-14 .--this is the table name you either have in existence or have created in step one above.
Declare @TablixColumns nvarchar(max) = ''
declare @TablixMembers nvarchar(max) = ''--loop through and create the header elements here based on the column names
--from the TmpTableForSSRSReport table definition SELECT top 100 percent
@TablixMembers = @TablixMembers + '<TablixMember />',
@TablixHeader = @TablixHeader + '<TablixCell><CellContents>_
<Textbox Name="Textbox' + cast(ROW_NUMBER() over (order by ORDINAL_POSITION) _
as varchar(50)) + '"><CanGrow>true</CanGrow><KeepTogether>true</KeepTogether>_
<Paragraphs><Paragraph><TextRuns><TextRun><Value>'+ replace(ltrim(rtrim(COLUMN_NAME)), _
'&','&amp;') +'</Value><Style /></TextRun></TextRuns><Style /></Paragraph></Paragraphs>_
<rd:DefaultName>Textbox' + cast(ROW_NUMBER() over (order by ORDINAL_POSITION) _
as varchar(50)) + '</rd:DefaultName><Style><Border><Color>LightGrey</Color>_
<Style>Solid</Style></Border><PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight>_
<PaddingTop>2pt</PaddingTop><PaddingBottom>2pt</PaddingBottom></Style></Textbox>_
</CellContents></TablixCell>'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TempTableName
order by ORDINAL_POSITION --GB. 2021-05-14 loop through and get the details.
--I separated this out just because code would have been too busy. SELECT top 100 percent @TablixColumns = @TablixColumns + '<TablixColumn><Width>1in</Width></TablixColumn>',@TablixDetails = @TablixDetails + '<TablixCell><CellContents><Textbox Name="'+ replace(replace(replace(replace(replace(replace(replace(replace(replace(ltrim(rtrim(COLUMN_NAME)),' ', '_'), '#', '_'), _'(','_'), ')','_'), '/','_'), '\','_'), '$','_'), '&','_'), '?','_')+'"><CanGrow>true</CanGrow><KeepTogether>true</KeepTogether><Paragraphs><Paragraph><TextRuns><TextRun><Value>=Fields!'+ replace(replace(replace(replace(replace(replace(replace(replace(replace(ltrim(rtrim(COLUMN_NAME)),' ', '_'), '#', '_'), _'(','_'), ')','_'), '/','_'), '\','_'), '$','_'), '&','_'), '?','_') +_'.Value</Value><Style /></TextRun></TextRuns><Style /></Paragraph></Paragraphs><rd:DefaultName>'+ replace(replace(replace(replace(replace(replace(replace(replace(replace(ltrim(rtrim(COLUMN_NAME)),' ', '_'), '#', '_'), '(','_'), _')','_'), '/','_'), '\','_'), '$','_'), '&','_'), '?','_') +_'</rd:DefaultName><Style><Border><Color>LightGrey</Color><Style>Solid</Style></Border><PaddingLeft>2pt</PaddingLeft><PaddingRight>2pt</PaddingRight><PaddingTop>2pt</PaddingTop><PaddingBottom>2pt</PaddingBottom></Style></Textbox></CellContents></TablixCell>'FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TempTableName
order by ORDINAL_POSITION --START OF THE XML building the XML here for the table header columns
set @TablixHeader = '<TablixRow>    <Height>0.25in</Height><TablixCells>' + @TablixHeader ---end or close tags for the xml closing the XML for the table header columns
set @TablixHeader = @TablixHeader + '</TablixCells></TablixRow>'set @TablixDetails = '<TablixRow>    <Height>0.25in</Height><TablixCells>' + @TablixDetails ---end or close tags for the xml closing the XML for the table header columns
set @TablixDetails = @TablixDetails + '</TablixCells></TablixRow>'
--GB. 2021-05-14 lets get the detail information in similar way select '<TablixRows>' + @TablixHeader + @TablixDetails + '</TablixRows>' as  TablixRows,
'<TablixColumns>' +  @TablixColumns +'</TablixColumns>' as [TablixColumns],
'<TablixMembers>' + @TablixMembers + '</TablixMembers>' as TablixMembers--GB. 2021-05-14 FINALLY
--GB. 2021-05-14 all you need to do really is to take the TablixRows
--and replace the TablixRows in the SSRS report.
--Same with the TablixColumns and TablixMembers. And that should do it. --GB. 2021-05-14 FINAL STEP. If you created a temporary table for this reason,
--just drop it here. This is commented out to avoid automatic dropping of a real table :)
--drop table TmpTableForSSRSReport--'

https://www.codeproject.com/Tips/5302654/Auto-Generate-a-Lot-of-Columns-in-Reporting-Servic

在Reporting Services (RDL)中自动生成大量列相关推荐

  1. WPF ListView中自动生成的列

    目录 介绍 为什么我们在这里 使用情况 其他可选的视觉样式 ColWidth属性 ColSort属性 ColCellTemplate属性 另一种样式选项--排序箭头颜色 代码 属性 排序装饰器 Aut ...

  2. 点滴积累【C#】---检验编号在本表中自动生成,与其他表无关

    检验编号在本表中自动生成,与其他表无关 效果: 描述:在本表中自动生成编号,与其他表无关. 调用: 1 protected void Page_Load(object sender, EventArg ...

  3. 如何:从 Windows 窗体 DataGridView 控件中移除自动生成的列

    如果将 DataGridView 控件设置为根据其数据源中的数据自动生成列,则可以选择忽略某些列.可以通过调用 Columns 集合的 Remove 方法进行此操作.或者,也可通过将 Visible ...

  4. webstorm如何自动换行_怎样在word中自动生成目录

           欢迎关注支持,谢谢!!! 用 Word 编排好一本书后,不用制作目录,可以用自动生成的方法生成,那么Word2016目录怎么自动生成呢?如果要自动生成目录,排版时就要设置好章节,如果等排 ...

  5. 【接口文档】Django restful framework中自动生成API文档

    Django restful framework中自动生成API文档 一.Swagger概述 1.引言 当接口开发完成,紧接着需要编写接口文档.传统的接口文档使用Word编写,or一些接口文档管理平台 ...

  6. android getter不起作用,java - 如何在Android Studio中自动生成getter和setter

    java - 如何在Android Studio中自动生成getter和setter Android Studio中是否有一个快捷方式可以自动生成给定类中的getter和setter? 14个解决方案 ...

  7. cad渐开线齿轮轮廓绘制_如何在机械CAD软件中自动生成齿轮

    在机械CAD软件中绘制图纸时,齿轮设计是非常常见的,其主要由于齿轮轮廓通常采用渐开线在生产中便于精确加工.那么怎么才能自动生成齿轮,让设计师能够快速进行绘制齿轮呢?接下来给大家详细介绍一下吧! CAD ...

  8. doc自动生成html,java web应用中自动生成文章html页面的实现.doc

    java web应用中自动生成文章html页面的实现 java web应用中自动生成文章html页面的实现 2009-11-09 00:24:15 标签:web开发,页面转换 [推送到技术圈] 版权声 ...

  9. 解决IDEA中自动生成返回值带final修饰的问题

    解决IDEA中自动生成返回值带final修饰的问题 参考文章: (1)解决IDEA中自动生成返回值带final修饰的问题 (2)https://www.cnblogs.com/andrew-303/p ...

最新文章

  1. EFMVC - ASP.NET MVC 3 and Entity Framework 4.1 Code First 项目介绍
  2. 解析nginx负载均衡
  3. android 下的网络图片加载
  4. html中css路径和xpath路径,6.1 HTML的简单介绍和快速获取XPath和CSS路径
  5. SpringDataJpa使用示例
  6. amd r5 m330 linux驱动下载,AMDAMD Radeon(TM) R5 M330 14.502.1014.0000显卡驱动官方正式版下载,适用于win8.1-64-驱动精灵...
  7. 脚本语言和工程语言_语言工程中有趣的事情
  8. 当实在受不了了,就开干吧!
  9. OpenCV3学习(11.8) FREAK描述符提取器
  10. 【Python3_进阶系列_004】Python3-工厂设计模式
  11. ssh和ssm的区别,好处
  12. python画七彩圆圈,用pygame做一个简单的python小游戏—七彩同心圆
  13. CodeSmith链接Oracle、MySQL数据库
  14. linux写makefile用tab报错,隐含规则 - linux makefile教程
  15. 商业综合体电气综合管理平台技术方案
  16. 视频批量添加滚动字幕,我1分钟就搞定了
  17. 16Python文本数据分析:新闻分类任务 (贝叶斯算法应用实例)
  18. Msfvenom使用指南
  19. Python操作Excel的Xlwings教程(八)——Excel使用VBA调用Python
  20. video标签无法播放视频

热门文章

  1. oracle 字符格式化,Oracle 字段格式化[日期,金额]
  2. python的django框架是干嘛的_Django框架在Python开发很重要为什么?
  3. UI设计素材干货|可临摹的时尚播放页面模板
  4. UI设计的扁平化图标模板素材
  5. ui kit模板,让新手设计师临摹提高!
  6. 建议把英语改成选修的计算机老师,中小学“变动”,英语改为副科?老师没意见家长却愁眉不展...
  7. .anonymous springsecurity需要登陆嘛_springSecurity之java配置篇
  8. python运算符讲解_举例讲解Python中的算数运算符的用法
  9. python串口实时读取数据画图_python串口绘图
  10. python matplotlib_高效使用 Python 可视化工具 Matplotlib