但有几个问题:
1, 无法实现让用户在报表页面选择输出格式,即显示对应的Toolbar,然后让用户选择不同的 Export Format;
2, 在代码写的方式,目前已经能实现 HTML / PDF / Excel / Word 方式的输出。
* 之前无法输入Excel ,原来原因仅是因为 ContentType 中的值写的不正规,非"application/excel",而是"application/vnd.ms-excel".
Public Function OpenReportWeb(ByVal p_ReportFormat As ReportType, Optional ByVal p_RS_Parameter() As ReportParameter = Nothing) As Byte()
Dim rs As New ReportingService
Dim nc As System.Net.NetworkCredential
Dim cc As New System.Net.CredentialCache
nc = New Net.NetworkCredential
nc.UserName = sUserName
nc.Password = sPassword
cc.Add(New Uri(zUrl), "NTLM", nc)
rs.Credentials = cc
rs.Url = zUrl
Dim credentials() As DataSourceCredentials
Dim cc2() As DataSourceCredentials
Dim reportDefinition As Byte() = Nothing
Dim result As Byte() = Nothing
Dim sFormat As String = "EXCEL" 'OK : HTML4.0 / PDF ; Not OK : MHTML / EXCEL
Select Case p_ReportFormat
Case ReportType.HTML
sFormat = "HTML4.0"
Case ReportType.PDF
sFormat = "PDF"
Case ReportType.Excel
sFormat = "EXCEL"
End Select
Dim sHistoryID As String = Nothing
Dim sDevInfo As String = "<DeviceInfo><Parameters>False</Parameters></DeviceInfo>" '
Dim parameters() As ParameterValue
Dim showHideToggle As String = Nothing
Dim encoding As String
Dim mimeType As String = "application/excel"
Dim warnings As Warning() = Nothing
Dim reportHistoryParameters As ParameterValue() = Nothing
Dim streamIDs As String() = Nothing
Dim sh As New SessionHeader
rs.SessionHeaderValue = sh
Dim definition As New DataSourceDefinition
definition.CredentialRetrieval = CredentialRetrievalEnum.Prompt
definition.ConnectString = sConnStr
definition.Enabled = True
definition.Extension = "SQL"
Try
Dim dsDefinition As DataSourceDefinition
Dim strURL As String
Try
dsDefinition = rs.GetDataSourceContents(sReportDataSourceName)
If Not (dsDefinition Is Nothing) Then
dsDefinition.ConnectString = sReportDataSource
dsDefinition.UserName = sSqlLoginID
dsDefinition.Password = sSqlLoginPwd
rs.SetDataSourceContents(sReportDataSourceName, dsDefinition)
End If
Catch ex As Exception
Throw ex
End Try
If Not IsNothing(p_RS_Parameter) Then
If p_RS_Parameter.Length > 0 Then
rs.SetReportParameters(sReportName, p_RS_Parameter)
End If
End If
rs.RequestEncoding = System.Text.UTF8Encoding.UTF8
result = rs.Render(sReportName, sFormat, sHistoryID, sDevInfo, Nothing, cc2, showHideToggle, encoding, mimeType, reportHistoryParameters, warnings, streamIDs)
sh.SessionId = rs.SessionHeaderValue.SessionId
'========================================================
'Response.Clear();
HttpContext.Current.Response.ClearHeaders()
HttpContext.Current.Response.ClearContent()
Dim sContentType As String
Select Case p_ReportFormat
Case ReportType.HTML
sContentType = "text/html"
Case ReportType.PDF
sContentType = "text/html"
Case ReportType.Excel
sContentType = "application/vnd.ms-excel"
End Select
'="application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/ms-word
HttpContext.Current.Response.ContentType = sContentType
HttpContext.Current.Response.AppendHeader("Context-HttpContext.Current.Disposition", "filename='Report'")
HttpContext.Current.Response.BinaryWrite(result)
HttpContext.Current.Response.End()
'========================================================
Catch ex As SoapException
Throw (ex)
End Try
Return result
End Function