Using a Redmine export as a spreadsheet data source?

Added by Joshua DeClercq over 4 years ago

I've played plenty with connecting Excel directly to a Redmine database for reporting, but that's not a good solution for regular users... so what I'm curious about is whether anyone has had luck loading a CSV export into Excel as a refreshable data source.

This would be a nice way for any user to take their saved queries and work with them entirely from a spreadsheet, rather than diving into Redmine's UI.

Replies (1)

RE: Using a Redmine export as a spreadsheet data source? - Added by Joshua DeClercq over 4 years ago

For anyone who is similarly interested in making an Excel workbook that can sync with a saved Redmine query, I've gotten far enough along in putting something together that I think it's best to share it. Consider the following VBA:

Sub GetCSV()

' Adapted from

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
Dim myURL As String
Dim oRespStr As String

username = InputBox(Prompt:="Redmine username:", Title:="Log in")
' Password is not masked. Wasn't sure how to do this and didn't look into it.
password = InputBox(Prompt:="Redmine password:", Title:="Log in")

' Fill out the following as appropriate to your server's configuration.
' This assumes you have two cells in your workbook somewhere named RMpid, for the project identifier,
' and RMqid, for the numerical query ID. You're welcome to just insert the values here instead.
myURL = "http://yourredmine/projects/" & Range("RMpid") & "/issues.csv?query_id=" & Range("RMqid")

Set webClient = CreateObject("WinHttp.WinHttpRequest.5.1")

' Update this URL, too.
webClient.Open "POST", "http://yourredmine/login", False
webClient.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 
webClient.send ("username=" & username & "&password=" & password & "&perm_login=on")

webClient.Open "GET", myURL, False

oResp = webClient.responseBody

' You'll need to have a reference enabled for MS Forms to do this part.
With New MSForms.DataObject
    .SetText StrConv(oResp, vbUnicode)
End With

' Assumes a sheet exists in your workbook named QueryData where the export will paste to.
Application.DisplayAlerts = False
Application.DisplayAlerts = True
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "QueryData" 

ActiveSheet.PasteSpecial Format:="Unicode Text", Link:=False, _
    DisplayAsIcon:=False, NoHTMLFormatting:=True
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
    :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), _
    Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1)), TrailingMinusNumbers:=True
ActiveSheet.ListObjects.Add(xlSrcRange, Range(Selection, ActiveCell.SpecialCells(xlLastCell).Offset(-1,0)), , xlYes).Name = _

' Assumes the first sheet in the workbook is what you want to look at after you're done.

Set webClient = Nothing


End Sub

It's a big ol' mess of different code and manual macros hacked together, but it works. Note the comments to get it going. When you run it, you'll be asked for your credentials, and it will proceed to populate and name a CSV export as a range of values.

There may be a much better way to parse the string into a table, but this worked, and I was in a rush.

If you set up a pivot table mapped to the data range's name (RedmineQuery), it should work reliably refresh after refresh. The best part is, it can be safely distributed to any Redmine user, since access will always be limited to what Redmine is already restricting them to.