2012年2月11日 星期六
report service 動態欄位寬度
經過研究之後,發現依照目前 Reporting 現有的功能,很難達成您的需求,需要客制化,因此目前有兩大類的做法:
Note:以下作法需需啟用 Reporting Services 中 [My Reports] 功能
1) 修改原有報表的 RDL 檔案的 XML,依據欄位的數量,平均分配每個欄位的寬度。修改完之後,需要另透過程式碼發佈至 Reporting 上,然後產生報表。如以下的做法:
· Here's a simple workaround if you absolutely need to get this working.
It's a hack, and you'll have to run this program every time you change the report, but it works.
1. You've probably already changed the visibility of all your dynamic columns to be an expression.
1. Make all your column widths in your table a weird number that doesn't occur elsewhere in your report: i.e. "1.23456in"
2. Save your report
3. Figure out the min and max number of dynamic-width columns, say 1 to 5 columns
4. Figure out the cumulitive width of dynamic-width columns: say 5 inches
5. Write a simple program (or just use the code below) to open the RDL or RDLC as a textfile, loop 5 times, do the text replace of "1.23456in" to (MAX_WIDTH / i), save as "dudeguy" + i + ".rdlc", where i is your loop counter
6. Change the logic of your interface program/webapp to reference "dudeguy" + num_columns
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Const MAX_WIDTH As Double = 5
Dim contents As String = File.OpenText("c:\dudeguy.rdlc").ReadToEnd
For i As Integer = 1 To 5
File.WriteAllText("c:\dudeguy" & i & ".rdlc", _
contents.Replace("1.23456in", FormatNumber(MAX_WIDTH / i, 5) & "in"))
Next
End Sub
End Class
以下是討論群組的文章:
Dynamic change of the column size and location of a matrix
http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/446dfbf5-b5d5-43b8-8e2e-18691c0e1cdf
Dynamic Column width for a report
http://social.msdn.microsoft.com/forums/en-US/sqlreportingservices/thread/9e6043f1-c458-4540-be59-d37b02feab8a/
2) 進階作法:直接根據報表資料來源的欄位多寡,動態產生整個 RDL 檔案,包含設定每個欄位的寬度等屬性,發佈至 Reporting Services,然後產生報表(可是用於多份報表)。詳細製作的細節如下,請參考:
使用报告服务 (Reporting Services) 创建即席报告应用程序 (Ad Hoc Report Application)
http://msdn.microsoft.com/zh-cn/library/aa902634(v=sql.80).aspx
用reporting service创建动态报表
http://blog.csdn.net/shankaipingo/article/details/590583
以下節錄片段程式碼:
' Table Columns
writer.WriteStartElement("TableColumns")
For i = 0 To m_Fields.Count - 1
writer.WriteStartElement("TableColumn")
Select Case m_Type(i)
Case "Decimal", "Int16", "Int32", "Int64", "Boolean"
writer.WriteElementString("Width", ".5in")
Case "DateTime"
writer.WriteElementString("Width", ".75in")
Case Else
writer.WriteElementString("Width", "1.5in")
End Select
writer.WriteEndElement() ' TableColumn
Next 'fieldName
writer.WriteEndElement() ' TableColumns
Best Regards,
訂閱:
文章 (Atom)