2012-03-11 403 views
0

我想以pdf格式(或任何其他便攜式格式)自動獲取SSRS報告。我的意思是當用戶按下按鈕而不是在報告視圖中查看報告時,它應該被轉換爲pdf以pdf格式顯示SSRS報告

如果可能,請給我Vb.Net代碼。

任何幫助將受到歡迎!

謝謝

回答

1

請試試這段代碼。

Private Sub GenerateReport(ParamList as hashtable) 
     rs.Credentials = System.Net.CredentialCache.DefaultCredentials 
     rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials 

     Dim historyID As String = Nothing 
     Dim deviceInfo As String = Nothing 
     Dim format As String = "PDF" 
     Dim results As Byte() 
     Dim encoding As String = String.Empty 
     Dim mimeType As String = String.Empty 
     Dim extension As String = String.Empty 
     Dim warnings As ReportExecution.Warning() = Nothing 
     Dim streamIDs As String() = Nothing 
     Dim filename As String = "C:\MyReport.pdf"  ' Change to where you want to save 
     Dim _reportName As String = "/Sales/MyReport" ' Change to be your report 
     Dim _historyID As String = Nothing 
     Dim _forRendering As Boolean = False 
     Dim _values As ReportingService.ParameterValue() = Nothing 
     Dim _credentials As ReportingService.DataSourceCredentials() = Nothing 
     Dim _parameters As ReportingService.ReportParameter() = Nothing 

     _parameters = rs.GetReportParameters(_reportName, _historyID, _forRendering, _values, _credentials) 

     Dim ei As ReportExecution.ExecutionInfo = rsExec.LoadReport(_reportName, historyID) 
     Dim parameters(_parameters.Length - 1) As ReportExecution.ParameterValue 

     for param as integer = 0 to _parameters.count - 1 
      parameters(param) = New ReportExecution.ParameterValue 
      parameters(param).Label = _parameters(param).name 
      parameters(param).Name = _parameters(param).name 
      parameters(param).Value = ParamList(param) 
     next 

     rsExec.SetExecutionParameters(parameters, "en-us") 
     results = rsExec.Render(format, deviceInfo, extension, mimeType, encoding, warnings, streamIDs) 

     Dim stream As New System.IO.FileStream(filename, IO.FileMode.OpenOrCreate) 

     stream.Write(results, 0, results.Length) 
     stream.Close() 
    End Sub 
+0

好的,謝謝!我會等待它。 – 2012-03-11 18:00:52

+0

你有沒有機會爲我找到代碼? – 2012-03-12 17:01:20