我有一个 ssis 包,它调用 ssrs 报告,除了保存 excel 输出的方式不同之外,它工作得很好。
仅将文件扩展名更改为 xlsx 是行不通的,它会损坏文件。我见过人们在文件名末尾使用“,51”的示例,但我不确定在我的特定代码中应用它。有人有什么想法吗?
提前非常感谢!
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.Diagnostics
<Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute()>
<System.CLSCompliantAttribute(False)>
Partial Public Class ScriptMain
Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
Enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Enum
Protected Sub SaveFile(ByVal url As String, ByVal localpath As String)
Dim loRequest As System.Net.HttpWebRequest
Dim loResponse As System.Net.HttpWebResponse
Dim loResponseStream As System.IO.Stream
Dim loFileStream As New System.IO.FileStream(localpath, System.IO.FileMode.Create, System.IO.FileAccess.Write)
Dim laBytes(256) As Byte
Dim liCount As Integer = 1
Try
loRequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
loRequest.Credentials = System.Net.CredentialCache.DefaultCredentials
loRequest.Timeout = 600000
loRequest.Method = "GET"
loResponse = CType(loRequest.GetResponse, System.Net.HttpWebResponse)
loResponseStream = loResponse.GetResponseStream
Do While liCount > 0
liCount = loResponseStream.Read(laBytes, 0, 256)
loFileStream.Write(laBytes, 0, liCount)
Loop
loFileStream.Flush()
loFileStream.Close()
Catch ex As Exception
End Try
End Sub
Public Sub Main()
Dim url, destination As String
destination = Dts.Variables("Folder_Destination").Value.ToString + "\" + Dts.Variables("ReportName").Value.ToString + Dts.Variables("OutPutDate").Value.ToString + ".xlsx"
url = Dts.Variables("ReportURL").Value.ToString + Dts.Variables("Location").Value.ToString + "&DateType=" + Dts.Variables("DateType").Value.ToString + Dts.Variables("ServiceArea").Value.ToString + "&StartDate=" + Dts.Variables("START_DATE").Value.ToString + "&EndDate=" + Dts.Variables("END_DATE").Value.ToString + "&rs:Format=EXCEL"
SaveFile(url, destination)
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
解决办法就是改变
&rs:Format=EXCEL
到
&rs:Format=EXCELOPENXML
解决方案在这里找到:
&rs:格式=EXCELOPENXML