问题描述
我有一张从 request.responseBody 获取的图像,如何在不使用计算机存储中的临时文件的情况下将其传递给 excel?
详情:
-
我在响应正文中使用带有图像的 rest API
-
我不想在我的桌面上有临时文件
-
挑战是将来自 API 的响应转换为 Pictures.Insert 或 Shapes.AddPicture
我正在使用这样的东西:
Sub GetPicAPI()
Dim myUrl As String ' path of image
Dim myPicture As Picture ' embedded image
Dim MyImage As String ' create string to receive image in text format
Dim myFile As String
Dim datim As String
Set request = CreateObject("MSXML2.ServerXMLHTTP")
datim = Format(CStr(Now),"yyyy_mm_dd_hh_mm_ss") 'datetime to generate file
myFile = Application.DefaultFilePath & "\phototemp" & datim & ".jpeg"
myUrl = "https://images.contoso.com/api/GetPic?pwd=1234=&id=1234res=low"
request.Open "GET",myUrl,False ' Where to get image
request.send ' Send the request for the webpage.
MyImage = StrConv(request.responseBody,vbUnicode) ' Get the webpage response text into response variable.
Open myFile For Output As #1 'open file to save image
Print #1,MyImage 'write to file
Close #1 'close file
Set myPicture = ActiveSheet.Pictures.Insert(myFile) 'put image into cell
End Sub
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)