私の上司から、社員のMantisバグデータベースをExcelにエクスポートするよう依頼されましたが、SQL Serverへのアクセスを許可することができず、プロセスを自動化する必要があります。"WinHttp.WinHttpRequest.5.1"経由でのMantis BTのエクスポート要求
私が使用できるのは、Excel(ODBCなし、手動エクスポートなし)だけです。
だから私はこれを行うために管理:
Dim webClient As Object
Dim i As Long, vFF As Long, oResp() As Byte
Dim vLocalFile As String
Dim username As String, password As String
username = "blahblah"
password = "blahblah"
Set webClient = CreateObject("WinHttp.WinHttpRequest.5.1")
// Opening the connection to the application with a POST, containing user, password, and "permanent login" checked
webClient.Open "POST", "http://10.202.157.40/mantisbt-1.1.6/login.php", False
webClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
webClient.send ("username=" & username & "&password=" & password & "&perm_login=on")
// Now I set the "project" to "All Projects" (as I want the view to display our 2200 bugs)
webClient.Open "POST", "http://10.202.157.40/mantisbt-1.1.6/set_project.php", False
webClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
webClient.send ("project_id=0")
// The problem is, the last query displays 624 bugs instead of 2200, but I noticed when I click on "Advanced Filters" it successfully show the 2200 bugs (tested under a web browser AND Excel : the ResponseText shows them)
webClient.Open "GET", "http://10.202.157.40/mantisbt-1.1.6/view_all_set.php?type=6&view_type=advanced", False
webClient.send
// And NOW I can download the CSV file... (and that's where something is wrong *)
webClient.Open "GET", "http://10.202.157.40/mantisbt-1.1.6/csv_export.php", False
webClient.send
oResp = webClient.responseBody
// Creating a file and then filling it...
vFF = FreeFile
vLocalFile = "_mantis_export.csv"
If Dir(vLocalFile) <> "" Then Kill vLocalFile
Open vLocalFile For Binary As #vFF
Put #vFF, , oResp
Close #vFF
// Freeing memory
Set webClient = Nothing
(*:CFコード)の前の行を、ResponseTextは "2200年のバグ" を示したので、すべてが最後のクエリ(csv_export.php)まで大丈夫でした。スクリプトは、ブラウザから呼び出されたときに、呼び出されたページとまったく同じものを表示します(ページに2つのバグがある場合、CSVには2つのバグが含まれます)。私の2200のバグがIE/Firefoxに表示されているので、CSVは私に2200のバグをもたらします。 しかし、レスポンステキストに2200のバグがあっても、CSVによって624個のバグが表示されます...「高度なフィルタ」ページを呼び出していないかのように:(
私は誰かが理解して助けてくれることを願っています。事前に)
おかげで、
デビッド
私はその機能を見ませんでした。ありがとう、本当に役に立ちました! –