分享方式:


教學課程:將文字格式化 (報表產生器)

在本教學課程中,您可以在 Reporting Services 編頁報表中練習以各種不同的方式格式化文字。 您可以實驗不同的格式。

使用資料來源和資料集設定空白報表之後,您可以挑選想要瀏覽的格式。 下圖顯示的報表與您在本教學課程中建立的報表相似。

格式化報表產生器報表的螢幕擷取畫面。

您在某個步驟故意出錯,所以知道錯誤的原因是什麼。 接著您要更正錯誤以便達到想要的效果。

完成此教學課程的估計時間:20 分鐘。

需求

如需需求的資訊,請參閱教學課程的先決條件 (報表產生器)

建立含資料來源和資料集的空白報表

建立空白報表

  1. 從電腦、Reporting Services Web 入口網站或 SharePoint 整合模式啟動報表產生器

    [新報表或資料集] 對話方塊隨即開啟。

    如果您看不到 [新增報表或資料集] 對話方塊,請按一下 [檔案] 功能表 > [新增]。

  2. [使用者入門] 對話方塊的左窗格中,確認已選取 [新增報表]

  3. 在右窗格中,選取 [空白報表]

建立資料來源

  1. 在 [報表資料] 窗格中,選取 [新增] > [資料來源]

    如果看不到 [報表資料] 窗格,請檢查 [檢視] 索引標籤上的 [報表資料]。

  2. 在 [名稱] 方塊中,輸入:TextDataSource

  3. 選取 [使用內嵌於報表中的連接] 。

  4. 驗證連線類型為 Microsoft SQL Server,然後在 [連接字串] 方塊中鍵入:Data Source = <servername>

    注意

    <servername>運算式 (例如 Report001) 會指定已安裝 SQL Server Database Engine 執行個體的電腦名稱。 本教學課程無須任何特定資料,只需要 SQL Server 資料庫的連線。 如果 [資料來源連線] 底下已列有資料來源連線,就可以選取該連線並移至下一個程序「建立資料集」。如需詳細資訊,請參閱取得資料連線的替代方式 (報表產生器)

  5. 選取 [確定]。

建立資料集

  1. 在 [報表資料] 窗格中,選取 [新增] > [資料集]。

  2. 確認資料來源為 TextDataSource

  3. 在 [名稱] 文字輸入框中,輸入:TextDataset

  4. 確認已選取 [文字] 查詢類型,然後選取 [查詢設計工具]

  5. 選取 [當成文字編輯]

  6. 將下列查詢貼入查詢窗格中:

    注意

    在本教學課程中,查詢已經包含資料值,因此不需要外部資料來源。 這樣會使查詢相當冗長。 在商業環境中,查詢不會包含資料。 這僅供教學之用。

    SELECT CAST('2015-01-05' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Accessories' as Subcategory,'Carrying Case' as Product, CAST(16996.60 AS money) AS Sales, 68 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Accessories' as Subcategory, 'Carrying Case' as Product, CAST(13747.25 AS money) AS Sales, 55 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Accessories' as Subcategory,'Carrying Case' as Product, CAST(9248.15 AS money) As Sales, 37 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Accessories' as Subcategory,'Tripod' as Product, CAST(1350.00 AS money) AS Sales, 18 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Accessories' as Subcategory,'Tripod' as Product, CAST(1800.00 AS money) AS Sales, 24 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Accessories' as Subcategory,'Tripod' as Product, CAST(1125.00 AS money) AS Sales, 15 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Accessories' as Subcategory,'Lens Adapter' as Product, CAST(1147.50 AS money) AS Sales, 17 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Accessories' as Subcategory,  'Lens Adapter' as Product, CAST(742.50 AS money) AS Sales, 11 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Accessories' as Subcategory,'Lens Adapter' as Product, CAST(1417.50 AS money) AS Sales, 21 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Accessories' as Subcategory, 'Carrying Case' as Product, CAST(13497.30 AS money) AS Sales, 54 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Accessories' as Subcategory, 'Carrying Case' as Product, CAST(11997.60 AS money) AS Sales, 48 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Accessories' as Subcategory, 'Carrying Case' as Product, CAST(10247.95 AS money) As Sales, 41 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Accessories' as Subcategory, 'Tripod' as Product, CAST(1200.00 AS money) AS Sales, 16 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Accessories' as Subcategory,'Tripod' as Product, CAST(2025.00 AS money) AS Sales, 27 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Accessories' as Subcategory,'Tripod' as Product, CAST(1425.00 AS money) AS Sales, 19 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Accessories' as Subcategory,'Lens Adapter' as Product, CAST(887.50 AS money) AS Sales, 13 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Accessories' as Subcategory, 'Lens Adapter' as Product, CAST(607.50 AS money) AS Sales, 9 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Accessories' as Subcategory,'Lens Adapter' as Product, CAST(1215.00 AS money) AS Sales, 18 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate,  'Lauren Johnson' as FullName,'Central' as Territory, 'Digital' as Subcategory,'Compact Digital' as Product, CAST(10191.00 AS money) AS Sales, 79 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate,  'Warren Pal' as FullName,'North' as Territory, 'Digital' as Subcategory, 'Compact Digital' as Product, CAST(8772.00 AS money) AS Sales, 68 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate,  'Fernando Ross' as FullName,'South' as Territory, 'Digital' as Subcategory, 'Compact Digital' as Product, CAST(10578.00 AS money) AS Sales, 82 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory,'Digital' as Subcategory, 'Slim Digital' as Product, CAST(7218.10 AS money) AS Sales, 38 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory,'Digital' as Subcategory, 'Slim Digital' as Product, CAST(8357.80 AS money) AS Sales, 44 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-05' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory,'Digital' as Subcategory,'Slim Digital' as Product, CAST(9307.55 AS money) AS Sales, 49 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate,  'Lauren Johnson' as FullName,'Central' as Territory, 'Digital' as Subcategory,'Compact Digital' as Product, CAST(3870.00 AS money) AS Sales, 30 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate,  'Warren Pal' as FullName,'North' as Territory, 'Digital' as Subcategory,'Compact Digital' as Product, CAST(5805.00 AS money) AS Sales, 45 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate,  'Fernando Ross' as FullName,'South' as Territory, 'Digital' as Subcategory, 'Compact Digital' as Product, CAST(8643.00 AS money) AS Sales, 67 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Lauren Johnson' as FullName,'Central' as Territory, 'Digital' as Subcategory, 'Slim Digital' as Product, CAST(9877.40 AS money) AS Sales, 52 as Quantity, 'Install Report Builder' as LinkText, 'https://go.microsoft.com/fwlink/?LinkId=154882' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Warren Pal' as FullName,'North' as Territory, 'Digital' as Subcategory, 'Slim Digital' as Product, CAST(12536.70 AS money) AS Sales, 66 as Quantity, 'Report Builder in SQL Server' as Link, 'https://go.microsoft.com/fwlink/?LinkId=160556' AS URL  
    UNION SELECT CAST('2015-01-06' AS date) as SalesDate, 'Fernando Ross' as FullName,'South' as Territory, 'Digital' as Subcategory, 'Slim Digital' as Product, CAST(6648.25 AS money) AS Sales, 35 as Quantity, 'What is New in Reporting Services (SSRS)' as Link, 'https://go.microsoft.com/fwlink/?LinkId=165064' AS URL  
    
  7. 選取 [執行] (!) 來執行查詢。

    查詢結果會成為可供報表顯示的資料。

  8. 選取 [確定]。

  9. 選取 [確定]。

將欄位加入至報表設計介面

如果希望擷取自資料集的欄位出現在報表中,您可能會不加思索地直接將欄位拖曳到設計介面。 此練習將點出為何這樣做無效,以及應該改用的方法。

將欄位加入至報表 (會得到錯誤的結果)

  1. 將 [FullName] 欄位從 [報表資料] 窗格拖曳到設計介面。

    報表產生器會建立一個內有運算式 (以 <Expr>表示) 的文字方塊。

  2. 選取執行

    您只會看到一筆記錄 Fernando Ross,這是查詢中依字母為第一順位的記錄。 欄位並未重複成顯示該欄位內的其他記錄。

  3. 選取 [設計] 返回設計檢視。

  4. 選取文字方塊中的運算式 <Expr>

  5. 在 [屬性] 窗格中,您會看到 [值] 屬性如下 (若未看見 [屬性] 窗格,請檢查 [檢視] 索引標籤上的 [屬性]):

    =First(Fields!FullName.Value, "TextDataSet")  
    

    First 函數設計為僅擷取欄位內的第一個值。

    直接將欄位拖曳到設計介面會建立文字方塊。 文字輸入框本身並非資料區,所以不會顯示來自報表資料集的資料。 位於資料區 (例如資料表、矩陣和清單) 內的文字方塊才會顯示資料。

  6. 選取文字方塊 (如果您已選取運算式,請按 ESC 鍵選取文字方塊),然後按下 DELETE 鍵。

將欄位加入至報表 (會得到正確的結果)

  1. 在功能區的 [插入] 索引標籤上,選取 [資料區] 區域內的 [清單]。 選取設計介面,然後進行拖曳以建立寬約 2 英吋且高約 1 英吋的方塊。

  2. 將 [FullName] 欄位從 [報表資料] 窗格拖曳到清單方塊中。

    這回報表產生器會建立一個內有運算式 [FullName] 的文字方塊。

  3. 選取執行

    此時方塊已經重複成顯示查詢中的所有記錄。

  4. 選取 [設計] 返回設計檢視。

  5. 選取文字方塊中的運算式。

  6. 在 [屬性] 窗格中,您會看到 [值] 屬性如下:

    =Fields!FullName.Value  
    

    透過將文字方塊拖曳到清單資料區,就可以顯示資料集內該欄位中的資料。

  7. 選取清單方塊,然後按下 DELETE 鍵。

將資料表加入至報表設計介面

建立這個資料表,以便能夠在其中放置超連結和旋轉的文字。

  1. 在 [插入] 索引標籤中,轉至 [資料表] > [資料表精靈]。

  2. 在 [新增資料表或矩陣精靈] 的 [選擇資料集] 頁面上,按一下 [選擇這份報表中現有的資料集或共用資料集]>[TextDataset (在此報表中)]>[下一步]

  3. 在 [排列欄位] 頁面上,將 [Territory]、[LinkText] 和 [Product] 欄位拖曳到 [資料列群組],並將 [Sales] 欄位拖曳到 [值],然後選取 [下一步]

    顯示如何在報表產生器中排列文字欄位的螢幕擷取畫面。

  4. 在 [選擇版面配置] 頁面上,清除 [展開/摺疊群組] 核取方塊以便看見整個資料表,然後選取 [下一步]

  5. 選取 [完成]。

  6. 選取執行

    資料表看起來似乎沒問題,不過卻有兩個總計資料列。 [LinkText] 資料行不需要 [Total] 資料列。

    顯示報表產生器報表中兩個總計的螢幕擷取畫面。

  7. 選取 [設計] 返回設計檢視。

  8. 選取 [LinkText] 資料行中的 [Total] 資料格,然後按住 SHIFT 鍵並選取其右邊的兩個資料格:[Product] 資料行中的空白資料格,以及 [Sales] 資料行中的 [Sum(Sales)] 資料格。

  9. 在選取這三個資料格之後,以滑鼠右鍵按一下其中一個資料格,然後選擇 [刪除資料列]。

    顯示如何從報表產生器報表中刪除資料列的螢幕擷取畫面。

  10. 選取執行

    現有,它只有一個 [總計] 資料列。

    顯示報表產生器報表中一個總計的螢幕擷取畫面。

在本節中,您要加入超連結指向上一節資料表中的文字。

  1. 選取 [設計] 返回設計檢視。

  2. 以滑鼠右鍵按一下含有 [LinkText] 的資料格,然後選取 [文字輸入框屬性]。

  3. 在 [動作] 索引標籤上,選取 [移至 URL]。

  4. 在 [選取 URL] 方塊中,選取 [URL],然後選擇 [確定]。

  5. 文字看起來並沒有任何不同。 您需要進行調整使其彷彿連結文字。

  6. 選取 [LinkText]

  7. 在 [主資料夾] 索引標籤 > [字型] 上,選取 [底線],並將 [色彩] 變更為 [藍色]。

  8. 選取執行

    文字現在看起來就像一個連結。

    顯示報表產生器報表中超連結文字的螢幕擷取畫面。

  9. 選取一個連結。 如果您的電腦已連接至網際網路,瀏覽器將會開啟報表產生器說明文章。

旋轉報表中的文字

在本節中,您要旋轉前幾節資料表中的部分文字。

  1. 選取 [設計] 返回設計檢視。

  2. 在包含 [Territory]. 的儲存格中選取

  3. 在 [首頁] 索引標籤的 [字型] 區段中,選取 [粗體] 按鈕。

  4. 如果 [屬性] 窗格並未開啟,請選取 [檢視] 索引標籤上的 [屬性] 核取方塊。

  5. 在 [屬性] 窗格中,尋找 WritingMode 屬性,並將其從 Default 變更為 Rotate270

    注意

    當 [屬性] 窗格中的屬性組織成類別目錄時,WritingMode 會位於 [當地語系化] 類別目錄中。 請確定您已選取資料格,而不是文字。 WritingMode 是文字方塊的屬性,並非文字的屬性。

    報表產生器報表中 [Territory] 欄位的螢幕擷取畫面。

  6. 在 [主資料夾] 索引標籤 > [段落] 區段上,選取 [中間] 和 [置中],將文字定位在儲存格的垂直及水平中心。

  7. 選取 [執行] (!)。

如今 [Territory] 資料格中的文字已呈垂直方向,從資料格底部往上書寫。

顯示 [Territory] 值已旋轉 270 度的螢幕擷取畫面。

將貨幣格式化

  1. 選取 [設計],切換到 [設計] 檢視。

  2. 選取含有 [Sum(Sales)] 的最上方資料表資料格,然後按住 SHIFT 鍵,再選取含有 [Sum(Sales)] 的底部資料表資料格。

  3. 在 [首頁] 索引標籤中,轉至 [數字] 群組>[貨幣] 按鈕。

  4. (選用) 如果您的地區設定為 [英文 (美國)],則預設範例文字會是 [$12,345.00]。 如果 [數字] 群組中未顯示範例貨幣值,請選取 [預留位置樣式]>[範例值]。

    報表產生器中 [範例值] 選項的螢幕擷取畫面。

  5. (選用) 在 [首頁] 索引標籤的 [數字] 群組中,選取[減少小數位數] 按鈕兩次,顯示沒有分的貨幣數字。

  6. 選取 [執行] (!) 預覽報表。

報表如今已顯示格式化的資料,更容易閱讀。

顯示重新格式化報表組建格式報表的螢幕擷取畫面。

顯示 HTML 格式的文字

  1. 選取 [設計],切換到 [設計] 檢視。

  2. 在 [插入] 索引標籤上,選取 [文字輸入框],然後在設計介面上選取並拖曳,以在資料表底下建立大約 4 英吋寬、3 英吋高的文字輸入框。

  3. 複製以下文字並將其貼入文字方塊中:

    <h4>Limitations of cascading style sheet attributes</h4>  
          <p>Only a basic set of <b>cascading style sheet (CSS)</b> attributes are defined:</p>  
          <ul><li>  
              text-align, text-indent  
            </li><li>  
              font-family, font-size  
            </li><li>  
              color  
            </li><li>  
              padding, padding-bottom, padding-top, padding-right, padding-left  
            </li><li>  
              font-weight  
            </li></ul>  
    
  4. 拖曳文字方塊的下邊緣,以納入所有文字。 您會注意到設計介面會隨著您拖曳而變得較大。

  5. 選取文字方塊中的所有文字。

  6. 以滑鼠右鍵按一下所有選取的文字,然後選取 [文字屬性]

    因為此屬性為文字,而非文字輸入框,因此可以在單一文字輸入框中混合使用純文字與使用 HTML 標記做為樣式的文字。

  7. 在 [一般] 索引標籤的 [標記類型] 底下,選取 [HTML - 將 HTML 標記解譯為樣式]。

  8. 選取 [確定]。

  9. 選取 [執行] (!) 預覽報表。

文字方塊中的文字會顯示成標頭、段落和項目符號清單。

顯示報表產生器報表中格式化文字的螢幕擷取畫面。

儲存報表

您可以將報表儲存至報表伺服器、SharePoint 文件庫或您的電腦上。

本教學課程會將報表儲存至報表伺服器。 如果您沒有報表伺服器的存取權,請將報表儲存在電腦中。

將報表儲存在報表伺服器上

  1. 在 [報表產生器] 按鈕中,選取 [另存新檔]

  2. 選取 [最近使用的網站和伺服器]。

  3. 選取或輸入您有權儲存報表之報表伺服器的名稱。

    「正在連接到報表伺服器」訊息隨即顯示。 連接完成時,您就會看見報表伺服器管理員指定為預設報表位置之報表資料夾的內容。

  4. 在 [名稱] 中,將預設名稱取代為您選擇的名稱。

  5. 選取 [儲存]。

報表就會儲存至報表伺服器。 您連接之報表伺服器的名稱會顯示在視窗底部的狀態列中。

將報表儲存到您的電腦中

  1. 在 [報表產生器] 按鈕中,選取 [另存新檔]

  2. 選取 [桌面]、[我的文件] 或 [我的電腦],然後瀏覽到您要儲存報表的資料夾。

  3. 在 [名稱] 中,將預設名稱取代為您選擇的名稱。

  4. 選取 [儲存]。

後續步驟