Function Hex2Base64(ByVal sHex)
Static oNode As Object
Dim a() As Byte
If Len(sHex) Mod 2 <> 0 Then
sHex = Left(sHex, Len(sHex) - 1) & "0" & Right(sHex, 1)
End If
If oNode Is Nothing Then
Set oNode = CreateObject("MSXML2.DOMDocument").createElement("Node")
End If
With oNode
.text = ""
.dataType = "bin.hex"
.text = sHex
a = .nodeTypedValue
.dataType = "bin.base64"
.nodeTypedValue = a
Hex2Base64 = .text
End With
End Function
Convert a hex string to base64 in an Excel function
题
I have a lengthy string of hex values to convert to base64.
I'm looking for a simple format cell function such as =Hex2b64(Hexstring)
that will accept any length of hex characters.
I have been using http://home.paulschou.net/tools/xlate/ to do my conversion manually. The conversion works and the data is received by all relevant databases and parsed appropriately.
The data I am receiving is hex represented binary, which has been converted in multiple blocks and concatenated into long hex strings in accordance with project documentation that I am not privy to.
A typical Input String would be:
Hex= 00014088F6650101393939393939392D30304646463238313030000343332353430342D35353FA10000002805900100002805
and the corresponding output would be:
B64 = AAFAiPZlAQE5OTk5OTk5LTAwRkZGMjgxMDAAA0MzI1NDA0LTU1P6EAAAAoBZABAAAoAF
解决方案
不隶属于 StackOverflow