Foxtable(狐表)用户栏目专家坐堂 → 如何将报表直接作为邮件正文发送


  共有1885人关注过本帖树形打印复制链接

主题:如何将报表直接作为邮件正文发送

帅哥哟,离线,有人找我吗?
zhimin
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:132 积分:1232 威望:0 精华:0 注册:2017/3/20 13:41:00
如何将报表直接作为邮件正文发送  发帖心情 Post By:2017/8/29 13:39:00 [只看该作者]

各位老师好!
如题!
以下是我生成报表的代码,我想实现点击“生成日报”按钮后,自动生成新邮件并将报表复制到邮件的正文中,但是不直接发送。
谢谢!
Dim Result As DialogResult
Result = MessageBox.Show(" 工作时间是否正确?","提示",MessageBoxButtons.YesNo)
If Result = DialogResult.Yes Then
    Dim Book As New XLS.Book(ProjectPath & "Attachments\日报.xls")
    Dim fl As String = ProjectPath & "Reports\日报.xls"
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Sheet(2,9).Value = "<填写时间 = #"& date.today &"#>"  '写入打印条件
    
    Book.Build() '生成细节区
    Book.Save(fl) '保存工作簿
    
    Dim App As New MSExcel.Application
    Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(ProjectPath & "reports\日报.xls")
    Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
    Dim Rg As MSExcel.Range = Ws.Cells
    'Rg.EntireColumn.AutoFit   '自动调整列宽
    Rg.EntireRow.AutoFit  '自动调整行高
    'Rg.WrapText = True
    App.Visible = True    
End If

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/8/29 15:11:00 [只看该作者]

 只能发图片

 

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\test.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
rg.copy

Dim client As New System.Net.Mail.SmtpClient()
client.Host = "smtp.qq.com"
client.Credentials = New System.Net.NetworkCredential("455189993@qq.com", "helen6849338.")
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network
Dim message As New System.Net.Mail.MailMessage("455189993@qq.com", "765427475@qq.com")
message.Subject = "图文邮件测试"
message.BodyEncoding = System.Text.Encoding.UTF8
message.IsBodyHtml = True

Dim body As String = "<html><body>正文内容</body></html>"
Dim content As String

'处理图片
Dim bmp = ClipBoard.GetImage

Dim ms As new System.Io.MemoryStream()
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)

Dim arr(ms.Length) As Byte
ms.Position = 0
ms.Read(arr, 0, ms.Length)
ms.Close()

Dim strbaser64 As String = Convert.ToBase64String(arr)

content &= "这是文字"
content &= "<DIV><IMG src='data:image/png;base64, " & strbaser64 & "'></IMG></DIV>"
content &= "也是文字"

message.Body = body.Replace("正文内容", content)

Try
    client.Send(message)
    msgbox("发送成功")
Catch ex As Exception
    msgbox("发送失败:" & ex.message)
End Try

app.quit


 回到顶部