t;html><body>" & vbCrLf & FragmentStart & Fragment
Case Else
nPos = InStr(nPos, Fragment, ">")
If nPos > 0 And nPos < Len(Fragment) Then
Fragment = Left$(Fragment, nPos) & FragmentStart & Mid$(Fragment, nPos + 1)
End If
End Select
nPos = InStr(1, Fragment, "</body", vbTextCompare)
Select Case nPos
Case 0
Fragment = Fragment & FragmentEnd & vbCrLf & "</body></html>"
Case Else
Fragment = Left$(Fragment, nPos - 1) & FragmentEnd & Mid$(Fragment, nPos)
End Select
'' Build the HTML given the description, the
'' fragment, and the context. And, replace the
'' offset placeholders in the description with
'' values for the offsets of StartHMTL,
'' EndHTML, StartFragment, and EndFragment.
'' Offsets need to be zero-based when placed on
'' clipboard, so subtract 1
'' from each before injecting.
Data = Description & Fragment
Data = Replace(Data, "aaaaaaaaaa", Format$(Len(Description), Fmt))
Data = Replace(Data, "bbbbbbbbbb", Format$(Len(Data), Fmt))
nPos = InStr(Data, FragmentStart) - 1
Data = Replace(Data, "cccccccccc", Format$(nPos + Len(FragmentStart), Fmt))
nPos = InStr(Data, FragmentEnd) - 1
Data = Replace(Data, "dddddddddd", Format$(nPos, Fmt))
'' Return attributed string.
HtmlDescribed = Data
End Function
在这里我无法对这个header的各个方面都进行详细的介绍,所以我只能讲解一些要点,你可以参考范例代码以及进行更深入的了解。你必须记住几个要点。Header中的偏移量是以零为基准的,因此你必须以此来调节你的字符串操作
程序(string-manipulation routine )。而且,如果你不仅需要读取而且需要编写header,你则必须了解字符数(number of digits )(比如Internet Explorer [IE] 是9,Word是10)。
最后,如果你只是将CF_HTML放入剪贴板,那么诸如Word和FrontPage等程序就处理不了了。你必须同时给剪贴板提供一个格式化的HTML的纯文本编译(plain-text rendition)以实现你所希望的结果。许多用来执行HTML-to-text转换的工具或是macho可能都需要执行自带的剖析器。但是Windows
程序员是不需要对HTML进行手动解析的。你可以用OS来取代这个日常任务:
Public Function Html2Text(ByVal Data As String) As String
Dim obj As Object
On Error Resume Next
Set obj = CreateObject("htmlfile")
obj.Open
obj.Write Data
Html2Text = obj.Body.InnerText
End Function
升级IE并不是解析HTML最快的方法,但却是相当好用的方法