我需要将zip文件从本地计算机转换为base64。
从Excel工作表行获取/读取路径名
将路径(zip文件)中的文件转换为base 64 string
将基础64值复制到Excel工作表中的下一列。
尝试了一些但没有工作。
当前代码:
Dim inByteArray, base64Encoded
inByteArray = readBytes("F:path/file.zip")
base64Encoded = encodeBase64(inByteArray)
Private Function readBytes(file)
Dim inStream
' ADODB stream object used
Set inStream = CreateObject("ADODB.Stream")
' open with no arguments makes the stream an empty container
inStream.Open
inStream.Type = TypeBinary
inStream.LoadFromFile(file)
readBytes = inStream.Read()
End Function
Private Function encodeBase64(bytes)
Dim DM, EL
Set DM = CreateObject("Microsoft.XMLDOM")
' Create temporary node with Base64 data type
Set EL = DM.CreateElement("tmp")
EL.DataType = "bin.base64"
' Set bytes, get encoded String
EL.NodeTypedValue = bytes
encodeBase64 = EL.Text
End Function
行inStream.type = TypeBinary
中的错误1:
参数类型错误,超出可接受的范围,或彼此冲突。
行readBytes = inStream.Read()
中的错误2:
在此上下文中不允许操作。
行EL.NodeTypedValue = bytes
中的错误3:
类型不匹配
答案 0 :(得分:2)
答案 1 :(得分:0)
谢谢你们:)
此外,对于excel表读取和写入,我使用了以下代码,这有助于实现我的目标。谢谢
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("F:\path")
Set ws = objWorkbook.Sheets("Sheet1")
Set ws2 = objWorkbook.Sheets("Sheet2")
rowcount = ws.usedrange.rows.count
for j = 1 to rowcount
fieldvalue = ws.cells(j,1)
inByteArray = readBytes(fieldvalue)
base64Encoded = encodeBase64(inByteArray)
ws2.cells(j,1) = base64Encoded
next