我想从 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
- 我应该将文件作为二进制文件还是其他类型的文件来处理?
- 我可以在文件仍然打开时上传文件吗(我想上传运行 VBA 的文件)?
我不确定我是否走在正确的轨道上。我也不确定标题和表单字段应该是什么。
感谢您的帮助。