从 SSRS 导出时如何获取命名的 Excel 工作表
每当将单页报表导出到 Excel 时,Excel 中的工作表均以报表名称命名。 如果报表有多个页面,则工作表将命名为sheet1、sheet2、.... 有没有办法在 SSRS 2005 中指定工作表名称?
解决方案: 经过一些谷歌搜索后发现了这个: 更改 SQL Server RS Excel 中的工作表名称:QnD XSLT
将尝试并发布更新(如果有效)。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
死灵术,以防万一所有链接都变暗:
将群组添加到您的报告
另外,建议在此处设置组表达式的排序顺序,以便选项卡将按字母顺序排序(或者您希望的排序方式)。
在组属性中设置分页符
现在您需要设置
成员(组)的 >PageName
,NOT Tablix 本身的PageName
。如果您获得了正确的对象,则属性网格的标题框中会显示“Tablix Member”(德语为 Tablix-Element)。 如果它是错误的对象,它会在属性网格的标题框中显示only“table/tablix”(没有member)。
注意:如果您获取 tablix 而不是 tablix 成员,它会在每个选项卡中放置相同的选项卡名称,后跟
(tabNum)
! 如果发生这种情况,您现在知道问题是什么了。Necromancing, just in case all the links go dark:
Add a group to your report
Also, be advised to set the sort order of the group expression here, so the tabs will be alphabetically sorted (or however you want it sorted).
Set the page break in the group properties
Now you need to set the
PageName
of the Tablix Member (group), NOT thePageName
of the Tablix itselfs.If you got the right object, if will say "Tablix Member" (Tablix-Element in German) in the title box of the properties grid. If it's the wrong object, it will say only "table/tablix" (without member) in the property grid's title box.
Note: If you get the tablix instead of the tablix member, it will put the same tab name in every tab, followed by a
(tabNum)
! If that happens, you now know what the problem is.要导出到不同的工作表并使用自定义名称,从 SQL Server 2008 R2 开始,可以使用分组、分页符和组的 PageName 属性的组合来完成此操作。
或者,如果您只想为单个工作表指定特定名称,请尝试使用报表上的 InitialPageName 属性。
有关更详细的说明,请查看此处:http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/
To export to different sheets and use custom names, as of SQL Server 2008 R2 this can be done using a combination of grouping, page breaks and the PageName property of the group.
Alternatively, if it's just the single sheet that you'd like to give a specific name, try the InitialPageName property on the report.
For a more detailed explanation, have a look here: http://blog.hoegaerden.be/2011/03/23/where-the-sheets-have-a-name-ssrs-excel-export/
在 SSRS 2008 R2 中使用页面组的 PageName 属性:
In SSRS 2008 R2 use PageName property of page group:
http://bidn.com/blogs/bretupdegraff/bidn-blog/234/new-features-of-ssrs-2008-r2-part-1-naming-excel-sheets-when-exporting-reports
为了在导出到 Excel 时添加选项卡名称,我使用了以下方法:
PageName
属性中。PageName
属性相同。To add tab names while exporting to excel, I used the following method:
PageName
property.PageName
property of the tablix object.将选项卡名称放在报表中的页眉或组 TableRow1 上,以便它将显示在每个 Excel 工作表上的“A1”位置。 然后在 Excel 工作簿中运行此宏。
Put the tab name on the page header or group TableRow1 in your report so that it will appear in the "A1" position on each Excel sheet. Then run this macro in your Excel workbook.
没有直接的方法。 您可以导出 XML,然后修改 XSLT 以正确格式化它(这是一种困难的方法)。 一种更简单的方法是编写多个没有显式分页符的报告,以便每个报告仅在 Excel 中导出到一张工作表中,然后编写一个可以为您合并的脚本。 无论哪种方式,都需要后处理步骤。
There is no direct way. You either export XML and then right an XSLT to format it properly (this is the hard way). An easier way is to write multiple reports with no explicit page breaks so each exports into one sheet only in excel and then write a script that would merge for you. Either way it requires a postprocessing step.
我能够按照 Valentino Vranken 和 rao 建议的更复杂的说明完成此操作,但这里有一个更简单的方法,用于更简单的报告。 这会将每个表放在单独的工作表上并在 Excel 中命名它们。 它似乎对 PDF 和 Word 等其他导出没有影响。
首先,在表格的
Tablix Properties
中的General
下,选中在之前或之后添加分页符
,这会将报表分隔成工作表。然后在每个表中,单击该表,然后在
将
分组
视图中的行组
一侧,选择父组或默认行组,然后在Group -> 下的 >Properties
视图 PageBreakBreakLocation
设置为None
,并将PageName
设置为工作表的名称。I was able to get this done following more complex instructions suggested by Valentino Vranken and rao , but here is a more simple approach , for a more simple report . This will put each table on a separate sheet and name them in Excel . It doesn't seem to have an effect on other exports like PDF and Word .
First in the
Tablix Properties
of of your tables underGeneral
, check eitherAdd a page break before or after
, this separates the report into sheets .Then in each table , click the table , then in the
Grouping
view , on theRow Groups
side , select the parent group or the default row group and then in theProperties
view underGroup -> PageBreak
setBreakLocation
toNone
andPageName
to the sheet's name .我发现实现工作表/分页符的最简单、最可靠的方法是使用矩形工具。
将页面分组到矩形或填充子报表中的页面的单个矩形内,如下所示:
我发现放置矩形的最快方法是将其绘制在您希望放置在矩形中的对象周围.
右键单击并在布局菜单中将矩形置于底层。
选择所有对象并稍微拖动它们,但确保它们落在原来的位置。 现在它们都将位于矩形中。
在矩形属性中,您可以将分页符设置为发生在矩形的开头或结尾,并且页面的名称可以基于表达式。
工作表的名称将与页面的名称相同。
重复的名称将在后缀括号中包含一个数字。
注意:确保名称是有效的工作表名称。
The simplest and most reliable way I've found of achieving worksheets/page-breaks is with use of the rectangle tool.
Group your page within rectangles or a single rectangle that fills the page in a sub-report, as follows:
The quickest way I've found of placing the rectangle is to draw it around the objects you wish to place in the rectangle.
Right click and in the layout menu, send the rectangle to back.
Select all your objects and drag them slightly, but be sure they land in the same place they were. They will all now be in the rectangle.
In the rectangle properties you can set the page-break to occur at the start or end of the rectangle and name of the page can be based on an expression.
The worksheets will be named the same as the name of the page.
Duplicate names will have a number in brackets suffix.
Note: Ensure that the names are valid worksheet names.
您可以使用 -sed- 和 -grep- 替换或写入每个文件的 xml 标头,指定所需的工作表名称,例如,sheetname1,在任何出现的标签之间:
You could use -sed- and -grep- to replace or write to the xml header of each file specifying your desired sheet name, e.g., sheetname1, between any occurrence of the tags:
虽然在对象上使用 PageName 属性实际上允许您自定义 Excel 中导出的工作表名称,但请注意,它还可以更新报表的命名空间定义,这可能会影响将报表重新部署到服务器的能力。
我有一份报告,我在 BIDS 中应用了此方法,并将我的命名空间从 2008 年更新到了 2010 年。当我尝试将报告发布到 2008R2 报告服务器时,我收到一个错误,指出命名空间无效,必须将所有内容恢复回来。 我确信我的情况可能是独一无二的,也许这不会总是发生,但我认为值得发帖。 一旦我发现问题,此页面帮助恢复命名空间(除了重置命名空间之外,还必须删除一些标签):
http://beatheadagainstwall.blogspot.com/2011/03/invalid-target-namespace-when-deploying.html? showComment=1440647962263#c5741523651495876761
While this usage of the PageName property on an object does in fact allow you to customize the exported sheet names in Excel, be warned that it can also update your report's namespace definitions, which could affect the ability to redeploy the report to your server.
I had a report that I applied this to within BIDS and it updated my namespace from 2008 to 2010. When I tried to publish the report to a 2008R2 report server, I got an error that the namespace was not valid and had to revert everything back. I am sure that my circumstance may be unique and perhaps this won't always happen, but I thought it worthy to post about. Once I found the problem, this page helped to revert the namespace back (There are tags that must also be removed in addition to resetting the namespace):
http://beatheadagainstwall.blogspot.com/2011/03/invalid-target-namespace-when-deploying.html?showComment=1440647962263#c5741523651495876761