These VBA and Google Apps Script classes abstract data from its location on its underlying worksheet. This means that all procedures that use that data no longer has to worry about ranges or physical data layout, and powerful data manipulation methods can be applied to data sets, such as google docs live import and json conversion. Since the classes are independent of the underlying worksheet structure or classes, code can be written for either VBA or Google Apps Script with only minor syntactical (vba -vs- javascript) differences . These classes have been in use by many people for the last year or so and are available free of charge from Excel Liberation at ramblings.mcpher.com where you can find many examples of their use.
3. Excel Liberation for details
Accessibility
cells are accessed .cell(row,column) where row and
column can be a name or a number.
Examples - VBA
dSet.cell ( 23, “id”).value()
dRow.cell(“id”).toString()
dSet.value(“mac”,”cost”)
dColumn(“mac”).toString()
dSet.column(“id”).value(“mac”)
4. Excel Liberation for details
Portability
The Google Apps Script version has the same syntax
(allowing for minor javaScript/VBA syntactical
differences)
Examples – Google Apps Script
dSet.cell ( 23, “id”).value();
dRow.cell(“id”).toString();
dSet.value(“mac”,”cost”);
dColumn(“mac”).toString();
dSet.column(“id”).value(“mac”);
5. Excel Liberation for details
Rollback
All manipulation is performed in memory, and only
committed, usually in one go, when ready
Examples
dRow.commit()
dSet.bigCommit()
Can be used to commit all or some data to a different sheet
Examples
dSet.bigCommit(wholeSheet(“anotherplace"))
dSet.bigCommit(wholeSheet(“anotherplace"), true,
Array(“id”,”target”), ”custom”, ”callout”)
6. Excel Liberation for details
Efficiency and maintainability
Sheet is only accessed once, to populate cDataSet,
and data is read all at once.
Examples
ds.populateData(wholeSheet(“InputData"))
Tables of data can be automatically discovered if
separated by blank lines and columns
Examples
ds.populateData(wholeSheet(“InputData"),,,,,,true)
7. Excel Liberation for details
Extensibility
Easy to extend with powerful capabilities
Examples
Populate a data set with JSON data
dSet.populateJSON jobject, Range("json1!$a$1")
Read a worksheet into a dset and convert it to JSON
dSet.populateData( Range("jSon2!$a$1"), , , , , , True).jObject.stringify()
Get the unique values in a column and sort them
dSet.column(“custom").uniqueValues(eSortAscending)
Get the a sheet directly from Google Docs
dSet.populateGoogleWire cb.httpGET(url), Range("Clone!$a$1")
8. Excel Liberation for details
Abstraction and iteration
No need to worry about physical location
Examples - VBA
for each dr in dSet.rows
debug.print dr.cell(“id”).value()
next dr
Examples - GAS
dSet.rows().forEach(function(dr) {
Logger.log(dr.cell(“id”).value());
});
Each class contains a reference to its address in the underlying sheet if
needed
Examples – each of these will return a Range object
dSet.where
dSet.column(“id”).where
dSet.row(24).where
9. Excel Liberation for details
Chaining
Extend other classes to pass data using cDataSet
Examples
Execute an SQL query to populate a Worksheet, then pass the resultant dataset to
serializer to create a json representation
ado.init(Range("testado!a1"))
.execute("imdb", , "where tomatometer<50")
.dSet
.jObject
.stringify()
10. Excel Liberation for details
Summary
These examples show some of the capabilities of
cDataSet abstraction.
For more detail, and to download see
www.mcpher.com