我需要转换一个图像内的Excel(或通过VBA)的到base64的(最后我将使XML输出)。
我该怎么做呢?我需要引用DOM吗?
我一直在读this question,但它只适用于文本字符串,而不是图像……
有谁有我能看到的代码吗?
发布于 2011-11-15 17:20:15
下面是一个函数。不记得从哪弄来的了。
Public Function EncodeFile(strPicPath As String) As String
Const adTypeBinary = 1 ' Binary file is encoded
' Variables for encoding
Dim objXML
Dim objDocElem
' Variable for reading binary picture
Dim objStream
' Open data stream from picture
Set objStream = CreateObject("ADODB.Stream")
objStream.Type = adTypeBinary
objStream.Open
objStream.LoadFromFile (strPicPath)
' Create XML Document object and root node
' that will contain the data
Set objXML = CreateObject("MSXml2.DOMDocument")
Set objDocElem = objXML.createElement("Base64Data")
objDocElem.dataType = "bin.base64"
' Set binary value
objDocElem.nodeTypedValue = objStream.Read()
' Get base64 value
EncodeFile = objDocElem.Text
' Clean all
Set objXML = Nothing
Set objDocElem = Nothing
Set objStream = Nothing
End Function
https://stackoverflow.com/questions/2043393
复制相似问题