在SSRS的程序框架下,一张报表有可能被多个客户端以不同的方式应用.譬如: Web页面可能需要HTML格式的报表,而打印时需要emf格式的报表.
在打印报表时,经常会先将它专换成emf格式的图片,再发送给打印客户端使用.那么如何实现之间的转换呢?
1 2 ' ReportingService是由web service的WSDL生成的代理类(Proxy) 3 Public Class RTLReportService 4 Inherits ReportingService 5 Implements RTSystems.Framework.Reporting.IReportService 6 7 Public Overloads Function Render( ByVal report As Framework.Reporting.IReport) As Byte ()() Implements Framework.Reporting.IReportService.Render 8 9 10 Dim deviceInfo As String = Nothing 11 Dim format As String = " IMAGE " 12 Dim firstPage As [ Byte ]() = Nothing 13 Dim encoding As String = Nothing 14 Dim mimeType As String = Nothing 15 Dim warnings As Warning() = Nothing 16 Dim reportHistoryParameters As ParameterValue() = Nothing 17 Dim streamIDs As String () = Nothing 18 Dim pages As [ Byte ]()() = Nothing 19 20 ' Build device info based on the start page 21 deviceInfo = [ String ].Format( " <DeviceInfo><OutputFormat>{0}</OutputFormat></DeviceInfo> " , " emf " ) 22 23 ' Exectute the report and get page count. 24 Try 25 ' Renders the first page of the report and returns streamIDs for 26 ' subsequent pages 27 ' firstPage = rs.Render(reportPath, format, Nothing, deviceInfo, Nothing, Nothing, _ 28 ' Nothing, encoding, mimeType, reportHistoryParameters, warnings, streamIDs) 29 30 ' Replacement code by sjs to handle parameters 31 32 Dim lstParams As New List( Of ParameterValue) 33 34 For Each param As RTSystems.Framework.Reporting.IReportParameter In report.Paramers 35 Dim paramValue As New ParameterValue() 36 paramValue.Name = param.Name 37 paramValue.Value = param.Value 38 lstParams.Add(paramValue) 39 Next 40 41 Dim parameters() As ParameterValue = lstParams.ToArray() 42 43 44 firstPage = Me .Render(report.ReportName, format , Nothing , deviceInfo, parameters, Nothing , _ 45 Nothing , encoding, mimeType, reportHistoryParameters, warnings, streamIDs) 46 47 48 ' The total number of pages of the report is 1 + the streamIDs 49 m_numberOfPages = streamIDs.Length + 1 50 pages = New [ Byte ](m_numberOfPages - 1 )() {} 51 52 ' The first page was already rendered 53 pages( 0 ) = firstPage 54 55 For pageIndex As Integer = 1 To m_numberOfPages - 1 56 ' Build device info based on start page 57 deviceInfo = [ String ].Format( " <DeviceInfo><OutputFormat>{0}</OutputFormat><StartPage>{1}</StartPage></DeviceInfo> " , " emf " , pageIndex + 1 ) 58 ' pages(pageIndex) = rs.Render(reportPath, format, Nothing, deviceInfo, Nothing, Nothing, _ 59 ' Nothing, encoding, mimeType, reportHistoryParameters, warnings, streamIDs) 60 pages(pageIndex) = Me .Render(report.ReportName, format , Nothing , deviceInfo, parameters, Nothing , _ 61 Nothing , encoding, mimeType, reportHistoryParameters, warnings, streamIDs) 62 Next 63 64 Finally 65 66 End Try 67 68 Return pages 69 End Function 70 71 End Class