基于报表生成数据馈送(报表生成器和 SSRS)Generating Data Feeds from Reports (Report Builder and SSRS)

Reporting ServicesReporting Services Atom 呈现扩展插件可生成 Atom 服务文档,该文档列出分页报表中可用的数据馈送以及来自报表中的数据区域的数据馈送。The Reporting ServicesReporting Services Atom rendering extension generates an Atom service document that lists the data feeds available from a paginated report and the data feeds from the data regions in a report. 使用此扩展插件生成与 Atom 兼容的数据馈送,这些馈送是可读的,并可以与使用从报表生成的数据馈送的应用程序进行交换。You use this extension to generate Atom-compliant data feeds that are readable and exchangeable with applications that can consume data feeds generated from reports. 例如,可以使用 Atom 呈现扩展插件生成随后可用在 Power Pivot 或 Power BI 中的数据馈送。For example, you can use the Atom rendering extension to generated data feeds that you can then use in Power Pivot or Power BI.

Atom 服务文档为报表中的每个数据区域至少列出一个数据馈送。The Atom service document lists at least one data feed for each data region in a report. 根据数据区域的类型以及数据区域显示的数据, Reporting ServicesReporting Services 可以自数据区域生成多个数据馈送。Depending on the type of data region and the data that the data region displays, Reporting ServicesReporting Services might generate multiple data feeds from a data region. 例如,矩阵或图表可以提供多个数据馈送。For example, a matrix or chart can provide multiple data feeds. Atom 呈现扩展插件创建 Atom 服务文档时,将为每个数据馈送创建一个唯一标识符,在 URL 中使用该标识符可以访问数据馈送的内容。When the Atom rendering extension creates the Atom service document, a unique identifier is created for each data feed and you use the identifier in the URL to access the content of the data feed.

Atom 呈现扩展插件为数据馈送生成数据的方式类似于逗号分隔值 (CSV) 呈现扩展插件将数据呈现到 CSV 文件的方式。The way that the Atom rendering extension generates data for a data feed is similar to how the Comma-Separated Value (CSV) rendering extension renders data to a CSV file. 类似于 CSV 文件,数据馈送是报表数据的平展表示形式。Like a CSV file, a data feed is a flattened representation of the report data. 例如,表中有一个行组对某组中的销售额进行加总时,会对每个数据行重复加总,并没有单独的行仅包含总和。For example, a table with a row group that sums the sales within a group repeats the sum in every data row and there is no separate row that contains only the sum.

可以使用 Reporting ServicesReporting Services Web 门户、Report Server 或与 Reporting ServicesReporting Services集成的 SharePoint 站点来生成 Atom 服务文档和数据馈送。You can generate Atom service documents and data feeds using the Reporting ServicesReporting Services web portal, Report Server, or a SharePoint site that is integrated with Reporting ServicesReporting Services.

Atom 应用于一对相关标准。Atom applies to a pair of related standards. Atom 服务文档符合 RFC 5023 Atom 发布协议规范,数据馈送符合 RFC 4287 Atom 联合格式协议规范。The Atom service document conforms to the RFC 5023 Atom publishing protocol specification and the data feeds conform to the RFC 4287 Atom syndication format protocol specification.

以下各节提供有关如何使用 Atom 呈现扩展插件的附加信息:The following sections provide additional information about how to use the Atom rendering extension:

在 SQL Server Data Tools 中,你可以在报表生成器和报表设计器中创建和修改分页报表定义 (.rdl) 文件。You can create and modify paginated report definition (.rdl) files in Report Builder and in Report Designer in SQL Server Data Tools. 每个创作环境提供了不同的方式来创建、打开和保存报表和相关项。Each authoring environment provides different ways to create, open, and save reports and related items.

作为数据馈送的报表Reports as Data Feeds

可以将生产报表作为数据馈送导出,或者可以创建主要目的是以数据馈送的形式向应用程序提供数据的报表。You can export a production report as a data feed or you can create a report whose primary purpose is provide data, in the form of data feeds, to applications. 将报表用作数据馈送为您在以下情况下提供了另一种向应用程序提供数据的方式:当数据不易通过客户端数据访问接口访问时,或者您更喜欢隐藏数据源的复杂性以使数据的使用更为简便时。Using reports as a data feed gives you an additional way to provide data to applications when the data is not easy to access through client data providers, or when you prefer to hide the complexity of the data source and make it simpler to use the data. 还可以使用 Reporting ServicesReporting Services 功能(如安全、计划和报表快照)管理用来提供数据馈送的报表,这是将报表用作数据馈送的另一个优点。Another benefit of using report data as a data feed is that you can use Reporting ServicesReporting Services features such as security, scheduling, and report snapshots to manage the reports that provide data feeds.

若要充分利用 Atom 呈现扩展插件,您应该理解报表是如何呈现到数据馈送中的。To get the most from the Atom rendering extension, you should understand how the report is rendered into data feeds. 如果使用现有报表,则若能预测这些报表能够生成的数据馈送将很有用;如果编写报表的目的是专门用作数据馈送,则重要的是能够包括数据并优化报表布局以充分利用数据馈送。If you are using existing reports, being able to predict what the data feeds the reports will generate is useful; if you are writing report specifically for use as data feeds, being able to include the data and fine tune the report layout to maximize the usefulness of the data feeds is valuable.

有关详细信息,请参阅从报表生成数据馈送(报表生成器和 SSRS)For more information, see Generate Data Feeds from a Report (Report Builder and SSRS).

Atom 服务文档(.atomsvc 文件)Atom Service Document (.atomsvc file)

Atom 服务文档指定针对一个或多个数据馈送的连接。An Atom service document specifies a connection to one or more data feeds. 该连接至少是指向生成馈送的数据服务的简单 URL。At a minimum, the connection is a simple URL to the data service that produces the feed.

使用 Atom 呈现扩展插件呈现报表数据时,Atom 服务文档将列出可用于报表的数据馈送。When you render report data by using the Atom rendering extension, the Atom service document lists the data feeds available for a report. 该文档为报表中的每个数据区域至少列出一个数据馈送。The document lists at least one data feed for each data region in the report. 表和仪表都只生成一个数据馈送;但矩阵、列表和图表可能生成多个数据馈送,具体取决于它们所显示的数据。Tables and gauges generate only one data feed each, but matrices, lists, and charts might generated multiple depending on the data they display.

下图显示了使用两个表和一个图表的报表。The following diagram shows a report that uses two tables and a chart.

RS_Atom_TableAndChartDataFeedsRS_Atom_TableAndChartDataFeeds

从此报表生成的 Atom 服务文档包括三个数据馈送:两个表各对应一个数据馈送,图表对应一个数据馈送。The Atom service document generated from this report includes three data feeds, one for each table and one for the chart.

矩阵数据区域可能包括多个数据馈送,这取决于该矩阵的结构。The matrix data regions might have more than one data feed, depending on the structure of the matrix. 下图显示的报表使用生成两个数据馈送的矩阵。The following diagram shows a report that uses a matrix that generates two data feeds.

RS_Atom_PeerDynamicColumnsRS_Atom_PeerDynamicColumns

该报表生成的 Atom 服务文档包括两个数据馈送,每个数据馈送对应一个动态对等列:Territory 和 Year。The Atom service document generated from this report includes two data feeds, one for each of the dynamic peer columns: Territory and Year. 下图显示了每个数据馈送的内容。The following diagram shows the content of each data feed.

RS_Atom_PeerDynamicDataFeedsRS_Atom_PeerDynamicDataFeeds

数据馈送Data Feeds

数据馈送是一个 XML 文件,它具有一致的不随时间变化的表格格式,以及在每次运行报表时都可能不同的可变数据。The data feed is an XML file that has a consistent tabular format that does not change over time and variable data that can be different each time the report is run. Reporting ServicesReporting Services 生成的数据馈送采用与 ADO.NET Data Services 生成的数据馈送相同的格式。The data feeds generated by Reporting ServicesReporting Services are in the same format as those generated by that ADO.NET Data Services.

数据馈送包含两部分:标题和数据。A data feed contains two sections: header and data. Atom 规范中定义了各部分中的元素。The Atom specification defines the elements in each section. 标题包括用于数据馈送的字符编码架构之类的信息。The header includes information such as the character encoding schema to use with the data feeds.

标题部分Header Section

以下 XML 代码显示数据馈送的标题部分。The following XML code shows the header section of a data feed.

<?xml version="1.0" encoding="utf-8" standalone="yes"?><feed xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">

<title type="text"></title>

<id>uuid:1795992c-a6f3-40ec-9243-fbfd0b1a5be3;id=166321</id>

<updated>2009-05-08T23:09:58Z</updated>

数据部分Data Section

数据馈送的数据部分为 Atom 呈现扩展插件生成的平展行集中的每一行都包含了一个 <entry> 元素。The data section of the data feeds contains one <entry> element for each row in the flattened rowset generated by the Atom rendering extension.

下图显示了使用组和总计的报表。The following diagram shows a report that uses groups and totals.

RS_Atom_ProductSalesSummaryCircledValuesRS_Atom_ProductSalesSummaryCircledValues

下面的 XML 在数据馈送中显示了来自该报表的 <entry> 元素。The following XML shows an <entry> element from that report in a data feed. 请注意,<entry> 元素包含该组的销售和订单的总计以及所有组的销售和订单的总计。Notice that the <entry> element includes the totals of the sales and orders for the group and the totals of sales and orders for all the groups. <entry> 元素包含报表中的所有值。The <entry> element includes all values on the report.

<entry><id>uuid:1795992c-a6f3-40ec-9243-fbfd0b1a5be3;id=166322</id><title type="text"></title><updated>2009-05-08T23:09:58Z</updated><author /><content type="application/xml"><m:properties>

<d:ProductCategory_Value>Accessories</d:ProductCategory_Value>

<d:OrderYear_Value m:type="Edm.Int32">2001</d:OrderYear_Value>

<d:SumLineTotal_Value m:type="Edm.Decimal">20235.364608</d:SumLineTotal_Value>

<d:SumOrderQty_Value m:type="Edm.Int32">1003</d:SumOrderQty_Value>

<d:SumLineTotal_Total_2_1 m:type="Edm.Decimal">1272072.883926</d:SumLineTotal_Total_2_1>

<d:SumOrderQty_Total_2_1 m:type="Edm.Double">61932</d:SumOrderQty_Total_2_1>

<d:SumLineTotal_Total_2_2 m:type="Edm.Decimal">109846381.399888</d:SumLineTotal_Total_2_2>

<d:SumOrderQty_Total_2_2 m:type="Edm.Double">274914</d:SumOrderQty_Total_2_2></m:properties></content>

</entry>

使用数据馈送Working with Data Feeds

由报表生成的所有数据馈送都包括生成数据馈送的数据区域父级范围内的报表项。All data feeds generated by the report include the report items that are in scope of the parent of the data region that generate the data feeds. . 设想有一个报表包含若干表和一个图表。Imagine a report that has several tables and a chart. 报表正文中的文本框提供有关每个数据区域的说明性文本。Text boxes in the report body provides descriptive text of each data region. 该报表生成的每个数据馈送中的每个条目都包括该文本框的值。Every entry in every data feed that the report generates includes the value of the text box. 例如,如果文本为“Chart displays monthly sales averages by sales region”,则所有三个数据馈送都会在每一行中包括此文本。For example, if the text is "Chart displays monthly sales averages by sales region", all three data feeds would include this text on each row.

如果报表布局包括分层数据关系,如嵌套数据区域,这些关系将包括在报表数据的平展行集中。If the report layout includes hierarchical data relationships, such as nested data regions, those relationships are included in the flattened rowset of report data.

嵌套数据区域的数据行通常较宽,特别是在嵌套表和矩阵包括组和总计的情况下。The data rows for nested data regions are typically wide, especially if the nested tables and matrices include groups and totals. 您可能会发现,将报表导出到数据馈送并且查看数据馈送以确定生成的数据就是所需数据,这会很有帮助。You might find it useful to export the report to a data feed and view the data feed to verify that the data generated is what you expected.

当 Atom 呈现扩展插件创建 Atom 服务文档时,将为数据馈送创建一个唯一标识符,在 URL 中使用该标识符可以查看数据馈送的内容。When the Atom rendering extension creates the Atom service document, a unique identifier is created for the data feed and you use the identifier in the URL to view the content of the data feed. 示例 Atom 服务文档(如上所示)包括 URL https://ServerName/ReportServer?%2fProduct+Sales+Summary&rs%3aCommand=Render&rs%3aFormat=ATOM&rc%3aDataFeed=xAx0x1The sample Atom service document, shown above, includes the URL https://ServerName/ReportServer?%2fProduct+Sales+Summary&rs%3aCommand=Render&rs%3aFormat=ATOM&rc%3aDataFeed=xAx0x1. 该 URL 标识报表 (Product Sales Summary)、Atom 呈现格式 (ATOM) 以及数据馈送的名称 (xAx0x1)。The URL identifies the report (Product Sales Summary), the Atom rendering format (ATOM), and the name of the data feed (xAx0x1).

报表项名称默认为报表项的报表定义语言 (RDL) 元素名称,这些名称经常较为直观或容易记忆。Report item names default to the report definition language (RDL) element names of the report items and often they are not intuitive or easy to remember. 例如,放入报表的第一个矩阵的默认名称为 Tablix 1。For example, the default name of the first matrix placed in a report is Tablix 1. 数据馈送使用这些名称。The data feeds use these names.

若要令数据馈送易于使用,可以使用数据区域的 DataElementName 属性来提供友好名称。To make the data feed easier to work with, you can use the DataElementName property of the data region to provide friendly names. 如果你为 DataElementName 提供值,数据馈送子元素 <d> 将使用该值,而不是使用默认的数据区域名称。If you provide a value for DataElementName the data feed subelement <d> will use is it instead of the default data region name. 例如,如果数据区域的默认名称为 Tablix1,而 DataElementName 设置为 SalesByTerritoryYear,则数据馈送中的 <d> 将使用 SalesByTerritoryYear。For example, if the default name of a data regions is Tablix1 and DataElementName set SalesByTerritoryYear then the <d> in the data feed uses SalesByTerritoryYear. 如果数据区域具有两个数据馈送(类似上述矩阵报表),则数据馈送中使用的名称为 SalesByTerritoryYear _Territory 和 SalesByTerritoryYear _Year。If the data regions has two data feeds like the matrix report described above, the names used in the data feeds are SalesByTerritoryYear _Territory and SalesByTerritoryYear _Year.

如果对报表显示的数据和数据馈送中的数据进行比较,则可能发现一些差异。If you compare the data shown on the report and the data in the data feed, you might notice some differences. 报表经常显示格式化的数值和时间/日期数据,但数据馈送包含非格式化的数据。Reports often shows formatted numeric and time/date data whereas the data feed contains unformatted data.

数据馈送用 .atom 文件扩展名保存。A data feed is saved with the .atom file name extension. 可以使用文本或 XML 编辑器(如记事本或 XML 编辑器)来查看文件结构和内容。You can use a text or XML editor such as Notepad or XML Editor to view the file structure and content.

平展报表数据Flattening Report Data

Atom 呈现器将报表数据提供为 XML 格式的平展行集。The Atom renderer provides report data as flattened rowsets in an XML format. 用于平展数据表的规则与用于 CSV 呈现器的规则相同,只有以下几点例外:The rules for flattening data tables are the same to those of the CSV renderer with a few exceptions:

  • 范围中的项平展到详细信息级别。Items in scope are flattened to the detail level. 不同于 CSV 呈现器,顶级文本框显示在写入数据馈送的每个条目中。Unlike the CSV renderer, the text boxes at the top level appear in each entry written to the data feed.

  • 在输出的每一行上呈现报表参数值。Report parameter values are rendered on each row of the output.

分层数据和分组数据必须进行平展才能以与 Atom 兼容的格式表示。Hierarchical and grouped data must be flattened in order to be represented in the Atom-compliant format. 呈现扩展插件可将报表平展为用于表示数据区域中嵌套组的树结构。The rendering extension flattens the report into a tree structure that represents the nested groups within the data region. 要平展报表:To flatten the report:

  • 行层次结构在列层次结构之前进行平展。A row hierarchy is flattened before a column hierarchy.

  • 行层次结构的成员在列层次结构的成员之前呈现到数据馈送。Members of the row hierarchy are rendered to the data feed before members of the column hierarchy.

  • 列按照以下顺序排序:表体中的文本框的顺序为从左到右,从上到下,后面紧跟数据区域,后者顺序为从左到右,从上到下。Columns are ordered as follows: text boxes in body order left-to-right, top-to-bottom followed by data regions ordered left-to-right, top-to-bottom.

  • 在数据区域中,列按照以下顺序排序:角成员、行层次结构成员、列层次结构成员,然后是单元。Within a data region, the columns are ordered as follows: corner members, row hierarchy members, column hierarchy members, and then cells.

  • 对等数据区域是一些共享一个公共数据区域或动态祖先的数据区域或动态组。Peer data regions are data regions or dynamic groups that share a common data region or dynamic ancestor. 对等数据通过平展后的树的分支进行标识。Peer data is identified by branching of the flattened tree.

有关详细信息,请参阅 表、矩阵和列表(报表生成器和 SSRS)For more information, see Tables, Matrices, and Lists (Report Builder and SSRS).

Atom 呈现规则Atom Rendering Rules

Atom 呈现扩展插件在呈现数据馈送时忽略以下信息:The Atom rendering extension ignores the following information when rendering a data feed:

  • 格式设置和布局Formatting and layout

  • 页眉Page header

  • 页脚Page footer

  • 自定义报表项Custom report items

  • 矩形Rectangles

  • 线条Lines

  • 映像Images

  • 自动小计Automatic subtotals

对其余的报表项进行排序,先从上到下排,再从左到右排。The remaining report items are sorted, from top to bottom, and then left to right. 之后,每一项将呈现到一列中。Each item is then rendered to a column. 如果报表有嵌套数据项(如列表或表),则会在每一行中重复它的父项。If the report has nested data items like lists or tables, the parent items are repeated on each row.

下表说明了呈现报表项时这些报表项的外观:The following table indicates the appearance of report items when rendered:

ItemItem 呈现行为Rendering behavior
Table 呈现方式为扩展该表,在只保留最起码的格式的情况下为每一行和每一列都分别创建行和列。Renders by expanding the table and creating a row and column for each row and column at the lowest level of detail. 小计行和小计列没有列标题或行标题。Subtotal rows and columns do not have column or row headings. 不支持钻取报表。Drillthrough reports are not supported.
矩阵Matrix 呈现方式为扩展该矩阵,在只保留最起码的格式的情况下为每一行和每一列都分别创建行和列。Renders by expanding the matrix and creating a row and column for each row and column at the lowest level of detail. 小计行和小计列没有列标题或行标题。Subtotal rows and columns do not have column or row headings.
列出List 为列表中每一明细行或实例呈现一个记录。Renders a record for each detail row or instance in the list.
子报表Subreport 对于内容的每个实例,都会重复它的父项。The parent item is repeated for each instance of the contents.
图表Chart 为每个图表值呈现具有所有图表标签的记录。Renders a record with all chart labels for each chart value. 来自系列和类别的标签采用平展的层次结构,并包含在图表值的行中。Labels from series and categories in hierarchies are flattened and included in the row for a chart value.
数据条Data bar 像图表一样呈现。Renders like a chart. 通常,数据条并不包括层次结构或标签。Typically, a data bar does not include hierarchies or labels.
迷你图Sparkline 像图表一样呈现。Renders like a chart. 通常,迷你图并不包括层次结构或标签。Typically, a sparkline does not include hierarchies or labels.
仪表Gauge 作为单个记录呈现,具有线性刻度的最小值和最大值、范围的起始和终止值,以及指针的值。Renders as a single record with the minimum and maximum values of the linear scale, start and end values of the range, and the value of the pointer.
指示器Indicator 作为单个记录呈现,具有活动状态名称、可用状态以及数据值。Renders as a single record with the active state name, available states, and the data value.
映射Map 为每个地图数据区域生成数据馈送。Generates a data feed for each map data region. 如果多个地图层使用相同数据区域,数据馈送将包含所有层的数据。If multiple map layers use the same data region, the data feed includes all of them. 该数据馈送包含一个记录,该记录包含地图层的每个地图成员的标签和值。The data feed includes a record with the labels and values for each map member of the map layer.

设备信息设置Device Information Settings

您可以更改此呈现器的某些默认设置,包括要使用的编码架构。You can change some default settings for this renderer, including the encoding schema to use. 有关详细信息,请参阅 ATOM Device Information SettingsFor more information, see ATOM Device Information Settings.

后续步骤Next steps

导出到 CSV 文件 Exporting to a CSV File
导出报表Export Reports

更多疑问?More questions? 请访问 Reporting Services 论坛Try asking the Reporting Services forum