You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VB.NET提取Outlook邮件HTMLBody中TABLE标签结果异常求助

问题:VBA迁移VB.NET后,Outlook邮件HTMLBody格式异常无法提取TABLE标签

我正尝试将自己编写的VBA函数迁移至VB.NET,该函数用于获取Outlook邮件并提取其HTMLBody中的TABLE标签。但两者输出结果不一致:VBA返回包含TABLE的标准HTML格式,而VB.NET返回的是从RTF转换的简易HTML。我已尝试所有BodyFormats,使用的引用与VBA完全相同,但仍无法得到标准HTML。查看Outlook源码发现正确格式应为VBA返回的样式,恳请提供解决建议。

VB.NET输出示例

<!-- Converted from text/rtf format -->
<P><FONT SIZE=2>TEXT0,<BR>
<BR>
<BR>
INTRO:<BR>
<BR>
A. TEXT1<BR>
<BR>
B TEXT2<BR>
<BR>
C. TEXT3<BR>
<BR>
D. TEXT4<BR>
<BR>
E. TEXT5 &amp; TEXT6<BR>
<BR>
<BR>

期望输出示例

<body lang=EN-US link=blue vlink=purple style='word-wrap:break-word'><div class=WordSection1><p><span style='font-family:Arial'>TEXT0<o:p></o:p></span></p>
<p><span style='font-family:Arial'><br>INTRO <o:p></o:p></span></p>
<p><span style='font-family:Arial'>A. TEXT1 <o:p></o:p></span></p>
<p><span style='font-family:Arial'>B. TEXT2 <o:p></o:p></span></p>
<p><span style='font-family:Arial'>C. TEXT3 <o:p></o:p></span></p>
<p><span style='font-family:Arial'>D. TEXT4 <o:p></o:p></span></p>
<p style='margin-bottom:12.0pt'><span style='font-family:Arial'>E. TEXT5

VB.NET代码

Function GetMailTable(Subject As String, daysAgo As Integer, ParamArray Keywords() As Object)
    Dim myOlApp As New Outlook.Application
    Dim objNamespace As Outlook.NameSpace = myOlApp.GetNamespace("MAPI")
    Dim objFolder As Outlook.MAPIFolder = objNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    Dim itm As Outlook.MailItem
    Dim Found As Boolean
    Dim strFilter As String
    Dim Subj As String = Subject
    Dim arrList As ArrayList = New ArrayList
    daysAgo = myDate.Subtract(previousBusinessDay(myDate, daysAgo)).TotalDays
    strFilter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & Chr(34) & " like '%" & Subj & "%'"
    Dim filtereditemssubj As Object = objFolder.Items.Restrict(strFilter)
    Dim filteredItems As Object = filtereditemssubj.Restrict("[ReceivedTime]>'" & Format(myDate.AddDays(-daysAgo), "dd/MM/yyyy") + " 00:00" & "'")
    filteredItems = filteredItems.Restrict("[ReceivedTime]<'", & Format(myDate.AddDays(-daysAgo).AddDays(1), "dd/MM/yyyy") + " 00:00" & "'")
    Dim htmlDoc As New mshtml.HTMLDocument
    Dim tables As mshtml.DispHTMLElementCollection
    Dim Table As mshtml.HTMLTable
    If filteredItems.Count = 0 Then
        Found = False
    Else
        Found = True
        For Each itm In filteredItems
            htmlDoc.HTMLBody = itm.HTMLBody
            tables = htmlDoc.getElementsByTagName("table")
            For Each Table In tables
                arrList.Add(Table)
            Next Table
        Next itm
    End If
    myOlApp = Nothing
    Return arrList
End Function

内容的提问来源于stack exchange,提问作者sickboy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 07:37:45