用户您的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