[英]Upload Excel xlsm file to php script using VBA
我想從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編碼。 遵循找到的示例代碼,但是在准備文件之前(在'---准備正文注釋之前),只需添加其他文本(表單項)即可
sPostData = sPostData & "--" & STR_BOUNDARY & vbCrLf & _
"Content-Disposition: form-data; name=""" & Name & """"
sPostData = sPostData & vbCrLf & vbCrLf & _
pvToUtf8(Value) & vbCrLf
...其中“ Name
和“ Value
是設計名稱以及要包含在服務請求中的實際文本。 對於功能pvToUtf8
實現,請查看此Google Cloud Print服務連接器 。 上面的摘錄取自同一連接器的pvRestAddParam
函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.