我想从 VBA 将 Excel xlsm 文件上传到 php 脚本。我找到了以下代码:
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
Dim strURL As String
Dim StrFileName As String
Dim FormFields As String
Dim path As String
Dim name As String
StrFileName = "c:\temp\ctc1output.xls"
strURL = "http://www.tri-simulation.com/P3/"
WinHttpReq.Open "POST", strURL, False
' Set the header
WinHttpReq.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
FormFields = """fileulp=" & StrFileName & """"
FormFields = FormFields + "&"
FormFields = FormFields + """sfpath=P3"""
WinHttpReq.Send FormFields
' Display the status code and response headers.
MsgBox WinHttpReq.GetAllResponseHeaders
MsgBox WinHttpReq.ResponseText
我不确定我是否走在正确的轨道上。
我也不确定标题和表单字段应该是什么。
感谢您的帮助。
最佳答案
您不需要对任何内容进行 base64 编码。关注 sample code you have found但在准备文件之前(在'---准备正文评论之前)只需像这样添加其他文本(表单条目)
sPostData = sPostData & "--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=""" & Name & """"
sPostData = sPostData & vbCrLf & vbCrLf & _
pvToUtf8(Value) & vbCrLf
...在哪里
Name
和 Value
是您想要包含在服务请求中的设计名称和实际文本。对于函数pvToUtf8
实现看看this Google Cloud Print service connector .上面的片段取自 pvRestAddParam
同一个连接器的功能。
关于vba - 使用 VBA 将 Excel xlsm 文件上传到 php 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15404460/