【发布时间】:2019-03-07 12:44:23
【问题描述】:
我有一个 java 代码,它从 MongoDB 获取数据,然后使用 Apache POI 创建一个包含此数据的 excel(.xls),但采用格式化的方式。
我的最终要求是将 excel 表中的最后一个工作表邮寄到一组邮件 ID。我无法使用 Java 邮件 API 来执行此操作,因为不会向我提供邮箱的 SMTP 详细信息。 截至目前,我计划在生成的 excel 中创建一个宏来发送数据。我创建的用于发送邮件的宏是:
Sub Send_Selection_Or_ActiveSheet_with_MailEnvelope()
'Working in Excel 2002-2016
Dim Sendrng As Range
On Error GoTo StopMacro
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Note: if the selection is one cell it will send the whole worksheet
Set Sendrng = Selection
'Create the mail and send it
With Sendrng
ActiveWorkbook.EnvelopeVisible = True
With .Parent.MailEnvelope
' Set the optional introduction field thats adds
' some header text to the email body.
.Introduction = "This is a test mail."
With .Item
.To = "iamnithinprakash@gmail.com"
.Subject = "My subject"
.Send
End With
End With
End With
StopMacro:
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
ActiveWorkbook.EnvelopeVisible = False
End Sub
但我不知道如何使用 java 创建这个宏。
【问题讨论】:
标签: java excel vba outlook apache-poi