-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
215 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/** | ||
* Creates a menu entry in the Google Docs UI when the document is opened. | ||
* | ||
* @param {object} e The event parameter for a simple onOpen trigger. To | ||
* determine which authorization mode (ScriptApp.AuthMode) the trigger is | ||
* running in, inspect e.authMode. | ||
*/ | ||
function onOpen() { | ||
'use strict'; | ||
try { | ||
|
||
var ui, context, menu, sheetType, docType, type; | ||
|
||
try { | ||
ui = DocumentApp.getUi(); | ||
context = DocumentApp; | ||
} catch (err) { | ||
Logger.log(err); | ||
ui = SpreadsheetApp.getUi(); | ||
context = SpreadsheetApp; | ||
} | ||
|
||
menu = ui.createAddonMenu(); | ||
|
||
if (context === SpreadsheetApp) { | ||
|
||
try { | ||
sheetType = JSON.parse(PropertiesService.getDocumentProperties().getProperty('sheetType')); | ||
} catch (enabled) { | ||
Logger.log(enabled); | ||
} | ||
type = (sheetType) ? sheetType.type : null; | ||
|
||
menu.addItem('Add Custom Functions', 'addFunctions'); | ||
|
||
} else if (context === DocumentApp) { | ||
try { | ||
docType = JSON.parse(PropertiesService.getDocumentProperties() | ||
.getProperty('docType')); | ||
} catch (enabled) { | ||
Logger.log(enabled); | ||
} | ||
|
||
// Documents do not have custom functions. | ||
|
||
} | ||
|
||
GRFNTools.appsuiteType = type; | ||
|
||
menu.addToUi(); | ||
|
||
} catch (elseErr) { | ||
Logger.log(elseErr); | ||
Logger.log('Not a supported Google Drive App'); | ||
} | ||
} | ||
|
||
/** | ||
* Runs when the add-on is installed. | ||
* | ||
* @param {object} e The event parameter for a simple onInstall trigger. To | ||
* determine which authorization mode (ScriptApp.AuthMode) the trigger is | ||
* running in, inspect e.authMode. (In practice, onInstall triggers always | ||
* run in AuthMode.FULL, but onOpen triggers may be AuthMode.LIMITED or | ||
* AuthMode.NONE.) | ||
*/ | ||
function onInstall(e) { | ||
onOpen(e); | ||
} | ||
|
||
/** | ||
* Displays a confirmation of function installation. | ||
*/ | ||
function addFunctions() { | ||
var title = 'stardotbmp/google-sheet-functions'; | ||
var message = 'The functions are now available in ' + | ||
'this spreadsheet. More information is available in the function help ' + | ||
'box that appears when you start using them in a forumula.'; | ||
var ui = SpreadsheetApp.getUi(); | ||
ui.alert(title, message, ui.ButtonSet.OK); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Applys a JOIN on an array or range. JOIN() doesn't work with ArrayFormula. This function works. | ||
* | ||
* @param {string} delimeter The delimeter to use between array values int he joned string. | ||
* @param {Range} range The specified range of cells. | ||
* @param {boolean} all A flag swith between returning all values in two-dimensions as a single result or to return rows joined * | ||
* @customfunction | ||
*/ | ||
function ARRAY_JOIN(delimeter, range, all) { | ||
|
||
delimeter = delimeter || ""; | ||
all = all ? all != false : false; | ||
|
||
var result = []; | ||
|
||
if (!range.map) { | ||
return "Invalid Parameters"; | ||
} | ||
|
||
result = range.map(function (row, i) { | ||
return row.filter(function(col) { | ||
return col != ''; | ||
}).join(delimeter); | ||
}) | ||
|
||
return !all ? result.map(function (r) { return [r]; }) : [result.join(delimeter)]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Returns a sum for each row of a given array. | ||
* @param {range} range The range or array to sum. | ||
* @customfunction | ||
*/ | ||
function ROW_SUM(range) { | ||
|
||
if (!range.map) { | ||
range = [[range]]; | ||
} | ||
|
||
return range.map(function(row){ | ||
return row.reduce(function(a, b) { return a + b; }, 0); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* Returns an array of indirect single cell references from different sheets. | ||
* @param {A2:A} sheets The column containing sheets' names. | ||
* @param {"E1"} ref The range to return from each sheet. | ||
* @param {string} key Value to match | ||
* @param {int} column The column from which to return a value | ||
* @param {int} headers The number of header rows to ignore in the lookup range | ||
* @customfunction | ||
*/ | ||
function INDIRECT_LOOKUP(sheets, ref, keys, column, headers) { | ||
var ss = SpreadsheetApp.getActiveSpreadsheet(), | ||
result = []; | ||
|
||
headers = headers || 0; | ||
|
||
var sheetList = (!sheets.map) ? [[sheets]] : sheets; | ||
var keyList = (!keys.map) ? [[keys]] : keys; | ||
|
||
if (keyList.length != sheetList.length) { | ||
if (keyList.length == 1) { | ||
keyList = Array(sheetList.length).fill(keys); | ||
} else { | ||
throw("Matching Keys should equal the number of referenced sheets"); | ||
} | ||
} | ||
|
||
for (var i = 0, l = sheets.length; i < l; i+=1) | ||
{ | ||
if (sheets[i] !='') { | ||
|
||
var values = ss.getSheetByName(sheets[i][0]).getRange(ref).getValues().slice(headers); | ||
|
||
var columnValues = values.filter(function(row){ | ||
|
||
return row[0] == keyList[i]; | ||
|
||
}).map(function(row, i){ return row[column-1]; }); | ||
|
||
result.push(columnValues); | ||
} else { | ||
result.push([0]); | ||
} | ||
} | ||
|
||
// balance column in results | ||
var maxCols = result.reduce(function(count, row){ return (count < row.length) ? row.length : count; },0); | ||
|
||
result = result.map(function(row){ | ||
if (row.length < maxCols) { | ||
return row.concat(Array(maxCols - row.length).fill(0)); | ||
} | ||
return row; | ||
}); | ||
|
||
//return JSON.stringify(result); | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Returns an array of indirect single cell references from different sheets. | ||
* @param {A2:A} sheets The column containing sheets' names or an array of sheet names | ||
* @param {"E1:E50"} range The single column range reference to totalise from each sheet. | ||
* @customfunction | ||
*/ | ||
function INDIRECT_SUM(sheets, range) { | ||
var ss = SpreadsheetApp.getActiveSpreadsheet(), | ||
result = []; | ||
|
||
if (!sheets.map) { | ||
sheets = [sheets]; | ||
} | ||
|
||
for (var i in sheets) | ||
{ | ||
if (sheets[i] =='') break; | ||
|
||
// result.push(sheets[i]); | ||
|
||
var values = ss.getSheetByName(sheets[i][0]).getRange(range).getValues() | ||
var sum = values.reduce(function(total, row) { | ||
|
||
if (row.length > 1) { | ||
throw("Only a single Column may be totalised"); | ||
} | ||
|
||
return total += row[0]; | ||
|
||
}, 0); | ||
|
||
result.push(sum); | ||
} | ||
return result; | ||
} |
This file was deleted.
Oops, something went wrong.