Reporting Services 中的分頁 (報表產生器與 SSRS)Pagination in Reporting Services (Report Builder and SSRS)

分頁指的是報表內的頁數,以及如何在這些頁面上排列報表項目。Pagination refers to the number of pages within a report and how report items are arranged on these pages. Reporting ServicesReporting Services 中的分頁會根據您用於檢視和傳遞報表的轉譯延伸模組而有所不同。Pagination in Reporting ServicesReporting Services varies depending on the rendering extension you use to view and deliver the report. 當您在報表伺服器上執行報表時,報表會使用 HTML 轉譯器。When you run a report on the report server, the report uses the HTML renderer. HTML 會遵循特定的一組分頁規則。HTML follows a specific set of pagination rules. 例如,如果您將相同的報表匯出至 PDF,系統就會使用 PDF 轉譯器,並套用另一組不同的規則,因此,報表的分頁就會不同。If you export the same report to PDF, for example, the PDF renderer is used and a different set of rules are applied; therefore, the report paginates differently. 若要為使用者成功設計容易閱讀的報表,並針對計畫用於傳遞報表的轉譯器最佳化該報表,您必須了解用於控制 Reporting ServicesReporting Services中之分頁的規則。To successfully design an easy-to-read report for your users that is optimized for the renderer that you plan to use to deliver your report, you need to understand the rules used to control pagination in Reporting ServicesReporting Services.

本主題討論實體頁面大小與報表配置,對手動分頁符號轉譯器轉譯報表的影響。This topic discusses the impact of the physical page size and the report layout on how hard page break renderers render the report. 您可以使用 [報表屬性] 窗格、 [屬性] 窗格或 [版面設定] 對話方塊來設定屬性,藉此修改實際頁面大小和邊界,並且將報表分為資料行。You can set properties to modify the physical page size and margins, and divide the report into columns, by using the Report Properties pane, the Properties pane, or the Page Setup dialog box. 按一下報表主體外面的藍色區域即可存取 [報表屬性]You access the Report Properties pane by clicking the blue area outside the report body. 按一下 [主資料夾] 索引標籤上的 [執行] ,然後按一下 [執行] 索引標籤上的 [版面設定] ,即可存取 [版面設定] 對話方塊。You access the Page Setup dialog box by clicking Run on the Home tab, and then clicking Page Setup on the Run tab.

注意

如果您將報表設計成單頁寬度,但它轉譯跨多個頁面,請確認報表主體 (包括邊界) 的寬度不超出實體頁面大小的寬度。If you have designed a report to be one page wide, but it renders across multiple pages, check that the width of the report body, including margins, is not larger than the physical page size width. 為避免將空頁面加入到您的報表,可以將容器邊角向左拖曳,來縮減容器的大小。To prevent empty pages from being added to your report, you can reduce the container size by dragging the container corner to the left.

注意

您可以在報表產生器以及 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.

報表主體The Report Body

報表主體是在設計介面上會顯示為空格的矩形容器。The report body is a rectangular container displayed as white space on the design surface. 它可以擴張或縮小以容納包含在其中的報表項目。It can grow or shrink to accommodate the report items contained within it. 報表主體不會反映實體頁面大小,而且事實上,報表主體的擴張可以超出實體頁面大小的界限而跨越多個報表頁面。The report body does not reflect the physical page size and, in fact, the report body can grow beyond the boundaries of the physical page size to span multiple report pages. Microsoft ExcelMicrosoft Excel、Word、HTML 和 MHTML 之類的某些轉譯器會轉譯根據頁面內容而擴張或縮小的報表。Some renderers, such as Microsoft ExcelMicrosoft Excel, Word, HTML and MHTML, render reports that grow or shrink depending on the contents of the page. 以這些格式轉譯的報表會針對螢幕檢視 (例如在網頁瀏覽器中) 最佳化。Reports rendered in these formats are optimized for screen-based viewing, such as in a Web browser. 這些轉譯器會在需要時加入垂直分頁符號。These renderers add vertical page breaks when required.

您可以設定報表主體的格式,讓其包含框線色彩、框線樣式,以及框線寬度。You can format the report body so that there is a border color, border style and border width. 您也可以加入背景色彩和背景影像。You can also add a background color and background image.

實體頁面The Physical Page

實體頁面大小就是紙張大小。The physical page size is the paper size. 您針對報表指定的紙張大小會控制轉譯報表的方式。The paper size that you specify for the report controls how the report is rendered. 以手動分頁符號格式轉譯的報表會根據實體頁面大小水平和垂直插入分頁符號,就可以在使用手動分頁符號檔案格式列印或檢視時,提供最佳化的閱讀經驗。Reports rendered in hard page break formats insert page breaks horizontally and vertically based on the physical page size to provide an optimized reading experience when printed or viewed in a hard page break file format. 以軟分頁符號格式轉譯的報表會根據實體頁面大小水平插入分頁符號,就可以在使用網頁瀏覽器檢視時,提供最佳化的閱讀經驗。Reports rendered in soft page break formats insert page breaks horizontally based on the physical size to provide an optimized reading experience when viewed in a Web browser.

根據預設,頁面大小為 8.5 x 11 英吋,但是您可以使用 [報表屬性] 窗格、[版面設定] 對話方塊,或變更 [屬性] 窗格中的 PageHeight 和 PageWidth 屬性來變更這個大小。By default, the page size is 8.5 x 11 inches but you can change this size by using the Report Properties pane, Page Setup dialog box or by changing the PageHeight and PageWidth properties in the Properties pane. 頁面大小不會擴張或縮小來容納報表主體的內容。The page size does not grow or shrink to accommodate the contents of the report body. 如果您要讓報表出現在單頁上,報表主體內的所有內容都必須容納在實體頁面中。If you want the report to appear on a single page, all the content within the report body must fit on the physical page. 如果無法容納在單頁中,而且您使用手動分頁符號格式,則報表將需要額外的頁面。If it does not fit and you use the hard page break format, then the report will require additional pages. 如果報表主體的擴張超過實體頁面的右邊緣,則會水平插入分頁符號。If the report body grows past the right edge of the physical page, then a page break is inserted horizontally. 如果報表主體的擴張超過實體頁面的下邊緣,則會垂直插入分頁符號。If the report body grows past the bottom edge of the physical page, then a page break is inserted vertically.

如果您要覆寫報表中定義的實體頁面大小,您可以針對要用於匯出報表的特定轉譯器,使用 [裝置資訊] 設定來指定實體頁面大小。If you want to override the physical page size that is defined in the report, you can specify the physical page size using the Device Information settings for the specific renderer that you are using to export the report. 如需詳細資訊,請參閱 Reporting Services 裝置資訊設定For more information, see Reporting Services Device Information Settings.

邊界Margins

邊界會從實體頁面尺寸的邊緣向內繪製到指定的邊界設定。Margins are drawn from the edge of the physical page dimensions inward to the specified margin setting. 如果報表項目擴充到邊界區域,則該項目會遭到裁剪,因此不會轉譯重疊的區域。If a report item extends into the margin area, it is clipped so that the overlapping area is not rendered. 如果您指定的邊界大小會使頁面的水平或垂直寬度等於零,邊界設定會預設為零。If you specify margin sizes that cause the horizontal or vertical width of the page to equal zero, the margin settings default to zero. 您可以使用 [報表屬性] 窗格、[版面設定] 對話方塊,或變更 [屬性] 窗格中的 TopMargin、BottomMargin、LeftMargin 和 RightMargin 屬性來指定邊界。Margins are specified using the Report Properties pane, Page Setup dialog box or by changing the TopMargin, BottomMargin, LeftMargin and RightMargin properties in the Properties pane. 如果您要覆寫報表中定義的邊界大小,您可以針對要用於匯出報表的特定轉譯器,使用 [裝置資訊] 設定來指定邊界大小。If you want to override the margin size that is defined in the report, you can specify the margin size using the Device Information settings for the specific renderer that you are using to export the report.

在配置邊界、資料行間距和頁首與頁尾的空間後剩餘的實體頁面區域稱為 「可用的頁面區域」(Usable Page Area)。The area of the physical page that remains after space is allocated for margins, column spacing, and the page header and footer, is called the usable page area. 只有在您以手動分頁符號轉譯器格式轉譯與列印報表時,才會套用邊界。Margins are only applied when you render and print reports in hard page break renderer formats. 下列影像指出實體頁面的邊界與可用的頁面區域。The following image indicates the margin and usable page area of a physical page.

具有邊界與可用區域的實體頁面。Physical page with margins and usable area.

新聞稿樣式資料行Newsletter-Style Columns

您的報表可以分割為多個資料行 (例如,新聞稿中的資料行),而且這些資料行會被視為在相同實體頁面上轉譯的邏輯頁面。Your report can be divided into columns, such as columns in a newspaper, that are treated as logical pages rendered on the same physical page. 這些資料行會從左到右、從上到下排列,而且在每個資料行之間,會以空格分隔。They are arranged from left to right, top to bottom, and are separated by white space between each column. 如果報表分割為一個以上的資料行,每個實體頁面都會垂直分割為多個資料行,而且其中每個資料行都會被視為一個邏輯頁面。If the report is divided into more than one column, each physical page is divided vertically into columns, each of which is considered a logical page. 例如,假設您的實體頁面上有兩個資料行。For example, suppose you have two columns on a physical page. 報表的內容會先填滿第一個資料行,然後再填滿第二個資料行。The content of your report fills the first column and then the second column. 如果報表無法完整容納在前兩個資料行內,報表會先填滿第一個資料行,然後再填滿下一頁的第二個資料行。If the report does not fit entirely within the first two columns, the report fills the first column and then the second column on the next page. 資料行會從左到右,從上到下,繼續填滿,直到所有報表項目都轉譯完成為止。Columns continue to be filled, from left to right, top to bottom until all report items are rendered. 如果您指定的資料行大小會使頁面的水平寬度或垂直寬度等於零,資料行間距會預設為零。If you specify column sizes that cause the horizontal width or vertical width to equal zero, the column spacing defaults to zero.

您可以使用 [報表屬性] 窗格、[版面設定] 對話方塊,或變更 [屬性] 窗格中的 TopMargin、BottomMargin、LeftMargin 和 RightMargin 屬性來指定資料行。Columns are specified using the Report Properties pane, Page Setup dialog box or by changing the TopMargin, BottomMargin, LeftMargin and RightMargin properties in the Properties pane. 如果您要使用未定義的邊界大小,您可以針對要用於匯出報表的特定轉譯器,使用 [裝置資訊] 設定來指定邊界大小。If you want to use a margin size that is not defined, you can specify the margin size using the Device Information settings for the specific renderer that you are using to export the report. 只有在您以 PDF 或影像格式轉譯與列印報表時,才會套用資料行。Columns are only applied when you render and print reports in PDF or Image formats. 下列影像指出包含資料行之頁面的可用頁面區域。The following image indicates the usable page area of a page containing columns.

顯示資料欄的實體頁面。Physical page with columns depicted.

分頁和頁面名稱Page Breaks and Page Names

當報表中包含頁面名稱時,報表可能會更容易閱讀,其資料也會更容易稽核及匯出。A report might be more readable and its data easier to audit and export when the report has page names. Reporting Services 報表中提供報表及 Tablix 資料區域 (資料表、矩陣和清單) 的屬性、群組和矩形,可控制重新編頁、重設頁碼,並在分頁時提供新的報表頁面名稱。Reporting Services provides properties for reports and tablix data regions (table, matrix, and list), groups, and rectangles in the report to control pagination, reset page numbers, and provide new report page names on page breaks. 不論報表以何種格式轉譯,這些功能都可以加強報表運作,尤其是在將報表匯出至 Excel 活頁簿時特別有用。These features can enhance reports regardless of the format in which reports are rendered, but are especially useful when exporting reports to Excel workbooks.

InitialPageName 屬性提供報表的初始頁面名稱。The InitialPageName property provides the initial page name of the report. 如果您的報表不包含要分頁的頁面名稱,則初始頁面名稱會用於分頁所建立的所有新頁面。If your report does not include page names for page breaks, then the initial page name is used for all the new pages created by page breaks. 使用初始頁面名稱不需要它。It is not required to use an initial page name.

轉譯的報表可以針對分頁所造成的新頁面,提供新的頁面名稱。A rendered report can provide a new page name for the new page that a page break causes. 若要提供頁面名稱,您要設定資料表、矩陣、清單、群組或矩形的 PageName 屬性。To provide the page name, you set the PageName property of a table, matrix, list, group, or rectangle. 不需要您在分頁時指定頁面名稱。It is not required that you specify page names on breaks. 如果您沒有指定,就會改用 InitialPageName 的值。If you do not, the value of InitialPageName is used instead. 如果 InitialPageName 也是空白的,則新頁面沒有名稱。If InitialPageName is also blank, the new page has no name.

Tablix 資料區 (資料表、矩陣和清單)、群組和矩形支援分頁。Tablix data regions (table, matrix, and list), groups, and rectangles support page breaks.

分頁包含下列屬性:The page break includes the following properties:

  • BreakLocation 會針對啟用分頁的報表元素,提供分頁的位置:開頭、結尾,或開頭和結尾。BreakLocation provides the location of the break for the page break enabled report element: at the start, end, or start and end. 若是群組,BreakLocation 可以位於群組之間。On groups, BreakLocation can be located between groups.

  • Disabled 會指出是否將分頁套用至報表元素。Disabled indicates whether a page break is applied to the report element. 如果這個屬性評估為 True,則會忽略分頁。If this property evaluates to True, the page break is ignored. 如果使用這個屬性,可以根據報表執行時的運算式,以動態方式停用分頁。This property is used to dynamically disable page breaks based on expressions when the report is run.

  • ResetPageNumber 會指出分頁時,是否應該將頁碼重設為 1。ResetPageNumberindicates whether the page number should be reset to 1 when a page break occurs. 如果這個屬性評估為 True,則會重設頁碼。If this property evaluates to True, the page number is reset.

    您可以在 [Tablix 屬性]、[矩形屬性] 或 [群組屬性] 對話方塊中設定 BreakLocation 屬性,但是您必須在報表產生器的 [屬性] 窗格中設定 Disabled、ResetPageNumber 和 PageName 屬性。You can set the BreakLocation property in the Tablix Properties, Rectangle Properties, or Group Properties dialog boxes, but you must set the Disabled, ResetPageNumber, and PageName properties in the Report Builder Properties pane. 如果 [屬性] 窗格中的屬性是依類別目錄組織,您將要在 [分頁] 類別目錄中尋找屬性。If the properties in the Properties pane are organized by category, you will find the properties in the PageBreak category. 若是群組, [分頁] 類別目錄位於 [群組] 類別目錄內。For groups, the PageBreak category is inside the Group category.

    您可以使用常數和簡單或複雜的運算式來設定 Disabled 和 ResetPageNumber 屬性的值。You can use constants and simple or complex expressions to set the value of the Disabled and ResetPageNumber properties. 不過,您無法搭配 BreakLocation 屬性使用運算式。However, you cannot use expression with the BreakLocation property. 如需撰寫和使用運算式的詳細資訊,請參閱運算式 (報表產生器及 SSRS)For more information about writing and using expressions, see Expressions (Report Builder and SSRS).

    在您的報表中,您可以使用 Globals 集合,撰寫參考目前頁面名稱或頁碼的運算式。In your report you can write expressions that reference the current page names or page numbers by using the Globals collection. 如需詳細資訊,請參閱內建的全域和使用者參考 (報表產生器及 SSRS)For more information, see Built-in Globals and Users References (Report Builder and SSRS).

命名 Excel 工作表頁籤Naming Excel Worksheet Tabs

當您將報表匯出至 Excel 活頁簿時,這些屬性相當實用。These properties are useful when you export reports to Excel workbooks. 當您匯出報表時,使用 InitialPage 屬性來指定工作表索引標籤名稱的預設名稱,並使用分頁和 PageName 屬性,為每個工作表提供不同的名稱。Use the InitialPage property to specify a default name for the worksheet tab name when you export the report, and use page breaks and the PageName property to provide different names for each worksheet. 由分頁所定義的每個新的報表頁面都會匯出至由 PageName 屬性的值所命名的不同工作表。Each new report page, defined by a page break, is exported to a different worksheet named by the value of the PageName property. 如果 PageName 是空白的,但是報表有一個初始頁面名稱,則 Excel 活頁簿中的所有工作表都會使用相同的名稱,也就是初始頁面名稱。If PageName is blank, but the report has an initial page name, then all worksheets in the Excel workbook use the same name, the initial page name.

如需報表匯出至 Excel 時,這些屬性如何運作的詳細資訊,請參閱匯出至 Microsoft Excel (報表產生器及 SSRS)For more information about how these properties work when reports are exported to Excel, see Exporting to Microsoft Excel (Report Builder and SSRS).

另請參閱See Also

頁面配置和轉譯 (報表產生器及 SSRS )Page Layout and Rendering (Report Builder and SSRS)