用戶您的SSRS創建報表輸出,您所需的內容。將報告部署到您的報告服務器。在SSIS中,使用腳本任務使用URL方法調用SSRS報告,將報告保存到本地併發送出去。以下是詳細信息(我正在使用vb,但您可以使用c#當然):
報告服務器上的報告的URL:例如
http://XX.XX.XX.XX/ReportServer%2fSOMEREPORTFOLDER%2fSOMEREPORT&rs:Command=Render&rs:Format=EXCEL「
上述
注渲染格式的Excel。
然後使用腳本任務下面的代碼保存到你的本地網絡。Drivemappinguser和Drivermappingpassword報告是訪問您的SSRS服務器。
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 daUser As String
daUser = Replace(Dts.Variables("DriveMappingUser").Value.ToString, "STORM\", "")
Dim labytes(256) As Byte
Dim licount As Integer = 1
Try
lorequest = CType(System.Net.WebRequest.Create(url), System.Net.HttpWebRequest)
lorequest.Credentials = New System.Net.NetworkCredential(daUser, Dts.Variables("DriveMappingPassword").Value.ToString, "Storm")
' lorequest.Credentials = System.Net.CredentialCache.DefaultCredentials
lorequest.Timeout = 1000 * 90 * 30 'timeout 30 minutes
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
MsgBox(ex.Message)
End Try
End Sub
在你的主要方法中使用這個來調用上面的方法,url是上面提到的報告url,vFilePath是保存報告的路徑
SaveFile(URL, vFilePath)
然後在腳本任務中使用此代碼發送帶有報告附件的電子郵件。 str_SmtpClient是您的smtp電子郵件服務器,str_UserName和str_Password用於訪問您的smtp服務器。
Protected Sub SendEmail(ByVal vFilePath As String)
Dim preMon = MonthName(DatePart(DateInterval.Month, DateAdd("m", -1, Now))) + " " + CStr(Year(DateAdd("m", -1, Now)))
Dim strFrom As String = "[email protected]"
Dim strTo As String = Dts.Variables("RecipientEmail").Value.ToString
Dim strSubject As String = "Some Reports " + preMon
Dim strBody As String = "Dear " + Dts.Variables("RecipientName").Value.ToString + vbNewLine + vbNewLine + "Please find attached to this email your Partner Payment Report for the month of " + preMon + "." + vbNewLine + vbNewLine + "To protect your confidentiality, the report has been password protected. The password will have already been issued to you previously, and will not be accompanied with this email. " + vbNewLine + vbNewLine + "If you have any questions, please don't hesitate to get in contact with Mark Robertson, at [email protected] " + vbNewLine + vbNewLine + "Many thanks, " + vbNewLine + vbNewLine + "Reporting Team"
Dim msg As New MailMessage(strFrom, strTo, strSubject, strBody)
msg.Attachments.Add(New Attachment(vFilePath))
Dim client As New SmtpClient(Dts.Variables("str_SmtpClient").Value, 587)
' client.EnableSsl = True
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.Credentials = New NetworkCredential(Dts.Variables("str_UserName").Value, Dts.Variables("str_Password").Value)
client.Send(msg)
Threading.Thread.Sleep(30000)
End Sub
最後在上面的代碼中你的主要方法調用
SendEmail(vFilePath)
重申:你有上面的數據表。一個組可以由'FIle'的前四個字符定義。您希望輸出由FIle排序的數據,並在每個組之後插入空白行? – billinkc
準確地bilinkc – Manus
其實這些組是ddmm格式 – Manus