For setting up D3Gas you'll need the library, and for background on D3 and Apps Script read Using D3 in server side Gas
You'll need the d3Gas library.
Then you can do this
var d3 = d3Gas.d3;
Unlike Excel and VBA, you can't get at worksheet functions from Apps Script. However D3.js has some useful functions that operate on arrays just like some of the Sheets built in functions. To demonstrate I've implemented a few below.
Where my input sheet looks like this.
And the results are this - the final column is the result using the built in worksheets to see that they match the d3 generated results in the 'result' column.
d3 operates on a single array, so passing a range with multiple rows isn't going to work. However, d3.merge() can be used to combine a range like b2:e7 into a single array so that things like d3.sum() work across the whole range., as in the example below (where values holds the matrix of values from range b2:e7)
is equivalent to
For more like this, see Google Apps Scripts snippets. Why not join our forum, follow the blog or follow me on twitter to ensure you get updates when they are available.
You want to learn Google Apps Script?
Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, available All formats are available now from O'Reilly,Amazon and all good bookshops. You can also read a preview on O'Reilly.
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Google Apps Scripts snippets > Using D3 in server side Gas >