Domanda

Il mio capo mi ha chiesto di esportazione del database Mantis bug del corp di Excel, ma non mi può dare accesso a SQL Server, e il processo deve essere automatizzata.

L'unica cosa che posso utilizzare è Excel (nessun ODBC, nessuna esportazione manuale).

Così sono riuscito a fare questo:

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 il codice) La linea di prima, il ResponseText ha mostrato "2200 bug", quindi tutto andava bene fino a quando l'ultima query (csv_export.php). Lo script, quando viene chiamato tramite un browser, mostra esattamente la stessa pagina, che ha chiamato (se la pagina ha mostrato 2 bug, il CSV conterrà 2 errori). Con i miei 2200 bug riportati in IE / Firefox, il CSV mi porta 2200 bug. Ma in Excel, anche se il ResponseText mostra 2200 bug, il CSV mi porta 624 bug ... Come se non avessi chiamato il "Filtro avanzato" pagina: (

Spero che qualcuno possa capire e aiutare me;)

Grazie in anticipo,

David

È stato utile?

Soluzione

Forse sarebbe più facile per voi da usare l'API SOAP? Il punto di ingresso è a http: //server/mantis/api/soap/mantisconnect.php .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top