The tagCloud class
Today’s post will demonstrate how to generate tagClouds from various sources in Excel. As an example we will use some tweets retrieved by the rest- Excel library
A ‘Mitt Romney’ type query generates this tagCloud
The VBA code to create this uses classes from the ramblings site: cTagCloud , cDataSet. and heatMap.
Public Sub testTag() Dim ds As New cDataSet, dr As cDataRow, tg As New cTagCloud tg.init , , 3, " " With ds.populateData(wholeSheet("tweetsentimentdetails"), , , , , , True) For Each dr In .Rows tg.collect dr.Cell("text").toString Next dr End With tg.results Sheets("tagout").Range("a1") End Sub
A single Cell
The example above reports on a complete worksheet column. Here’s how to do a single cell, and is in the spirit of many posts such as rest-excel-json-excel in one line of code
Newt Gingrich’s wikipedia entry gives this
with this one liner.
Public Sub testTagSingleCell() Dim tg As New cTagCloud tg.init(, , 5, " ").collect( _ Sheets("singleTag").Range("a1").Value _ ).results Sheets("singleTag").Range("b1") End Sub
Multiple tags
Finally, here’s how to consolidate multiple tags from multiple workbooks, this time comparing Obama and Romney sentiment on tax and charity.
and here is the code,
Public Sub testWorkbookTag() Dim ds As cDataSet, dr As cDataRow, tg As cTagCloud, drin As cDataRow Dim din As cDataSet Set din = New cDataSet din.populateData wholeSheet("tagBook"), , , , , , True For Each drin In din.Rows Set tg = New cTagCloud tg.init , , 3, " " Set ds = New cDataSet With ds.populateData(wholeSheet(drin.Cell("sheet").toString), _ , , , , , True) For Each dr In .Rows tg.collect dr.Cell("text").toString Next dr tg.results drin.Cell("tags").where End With Next drin End Sub
You can read more about this and download these and other examples at the ramblings site. Although the examples here are based on tweet data, you can of course use any Excel data.