我确信它可以在一个有很多帮助列的公式中完成,但它会是多么的一团糟。这里有一些 VBA 可以做你想做的。
Public Function KeyValueToHtml(ByVal sKeyValue As String) As String
Dim vaPipe As Variant
Dim vaColon As Variant
Dim i As Long
Dim aReturn() As String
vaPipe = Split(sKeyValue, "|")
ReDim aReturn(LBound(vaPipe) To UBound(vaPipe))
For i = LBound(vaPipe) To UBound(vaPipe)
vaColon = Split(vaPipe(i), ":")
aReturn(i) = Tag(Tag(vaColon(0), "td") & vbNewLine & Tag(vaColon(1), "td"), "tr", , True)
Next i
KeyValueToHtml = Tag(Join(aReturn, vbNewLine), "table", , True)
End Function
Function Tag(ByVal sValue As String, ByVal sTag As String, _
Optional ByVal sAttr As String = "", Optional ByVal bIndent As Boolean = False) As String
Dim sReturn As String
If Len(sAttr) > 0 Then
sAttr = Space(1) & sAttr
End If
If bIndent Then
sValue = vbTab & Replace(sValue, vbNewLine, vbNewLine & vbTab)
sReturn = "<" & sTag & sAttr & ">" & vbNewLine & sValue & vbNewLine & "</" & sTag & ">"
Else
sReturn = "<" & sTag & sAttr & ">" & sValue & "</" & sTag & ">"
End If
Tag = sReturn
End Function