Thursday, July 18, 2013

Google Spreadsheet Script to convert an Array into a Martix


( by 
Francois Jooste )

Hello Everyone,

Im working on a interactive map of customer installations. I need to increase the Latitude and Longitude by .15 of a decimal point, so the map wont show exact customer residential information.

I don't know much about formulas, but there will be about 5,000 cells of data to alter.

Here is a test doc for help:

Thanks in advanced!


Have a look at the following screenshot:

I have the following formula in Cell C7:


the above formula is a custom function k() that I have written and inserted in Script.

Have a look at the following code:


function k() {
  var values = arguments[0], returnvalues = new Array();
  for(var i=0;i<(values.length)/7;i++) {
    returnvalues[i] = new Array();
    for(var j=0;j<7;j++) returnvalues[i].push([values[(i*7)+j]]);
  return returnvalues;


put the above code in your script editor, and then you can use it directly in your Google Spreadsheet or you can use its functionality in the Google Apps Script.

Now, insert the range in function k(), like:

and then you will get the matrix of this array of format ( 7 X N ).
And If you are not much familiar with scripts then check out the following link: 

I hope the above solution will help you, and if you need more help then please do comment below on this blog itself, I will try to help you out.

I also take up private and confidential projects:
If this blog post was helpful to you, and if you think you want to help me too and make my this blog survive then please donate here: 


No comments:

Post a Comment