在 Outlook 电子邮件中发送查询结果,格式为 table

Send query result in Outlook Email with Number formatted table

我想在 Outlook 中发送一封电子邮件,其中包含我在 Access 中的查询结果。电子邮件的正文包含带有结果的 table (columns/rows)。当值为数字时,我想使用带有逗号 xx,xxx 的数字格式。

我回收了我在这里找到的这段代码。如何格式化 table 输出?

Public Sub NewEmail()

    Dim olApp As Object
    Dim olItem As Variant
    Dim db As DAO.Database
    Dim rec As DAO.Recordset
    Dim strQry As String
    Dim aHead(1 To 3) As String
    Dim aRow(1 To 3) As String
    Dim aBody() As String
    Dim lCnt As Long

    'Create the header row
    aHead(1) = "Date"
    aHead(2) = "Request Type"
    aHead(3) = "Total" 'I want this to be comma separate number format?

    lCnt = 1
    ReDim aBody(1 To lCnt)
    aBody(lCnt) = "<HTML><body><table border='2'><tr><th>" & Join(aHead, "</th><th>") & "</th></tr>"

    'Create each body row
    strQry = "SELECT * From Email_Query"
    Set db = CurrentDb
    Set rec = CurrentDb.OpenRecordset(strQry)

    If Not (rec.BOF And rec.EOF) Then
        Do While Not rec.EOF
            lCnt = lCnt + 1
            ReDim Preserve aBody(1 To lCnt)
            aRow(1) = rec("Test1")
            aRow(2) = rec("Test2")
            aRow(3) = rec("Test3")
            aBody(lCnt) = "<tr><td>" & Join(aRow, "</td><td>") & "</td></tr>"
            rec.MoveNext
        Loop
    End If

    aBody(lCnt) = aBody(lCnt) & "</table></body></html>"

    'create the email
    Set olApp = CreateObject("Outlook.application")
    Set olItem = olApp.CreateItem(0)

    olItem.display
    olItem.To = "example@example.com"
    olItem.Subject = "Test E-mail"
    olItem.htmlbody = Join(aBody, vbNewLine)
    olItem.display

End Sub

尝试这样的事情:

            aRow(1) = Format(rec("YourDateField"), "yyyy-mm-dd")
            aRow(2) = rec("YourRequestType")
            aRow(3) = Format(rec("YourTotal"), "0.000")

如果留下一个点作为小数点分隔符,请尝试:

            aRow(3) = Replace(LTrim(Str(rec("YourTotal"))), ".", ",")

如果逗号是您的千位分隔符,请尝试:

            aRow(3) = Format(rec("YourTotal"), "00,000")