├── ColumnTransposer_.js ├── Lookup_.js ├── README.md ├── SumColArray_.js ├── WhseEmailPasser_.js ├── cleanArray_.js ├── clearSheets.js ├── cloneObj_.js ├── dupsExpose_.js ├── elimDupsInArray_.js ├── exportRange_.js ├── frenchDate_.js ├── gco_.js ├── getFirstEmptyRowUsingArray_.js ├── importRange_.js ├── isDate_.js ├── isEmpty_.js ├── isEven_.js ├── moneyMath_.js ├── objToString_.js ├── objectify_.js ├── pad_.js ├── pauseComp_.js ├── queryNegetive_.js ├── setRowColors_.js ├── subDaysFromDate_.js ├── testOrCreateSheet_.js └── uniDateTime_.js /ColumnTransposer_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | /* 3 | Benefit of this script is: 4 | - Allows you to send the function to arrays of columns and compile them or add them side by side 5 | - You can send as many parameters as you need 6 | 7 | Search terms: 8 | - Add two columns together / add one column to another one / concatenate two columns / join two columns / add one array to another array / concatenate arrays / join array / add array to side of another array / transpose array 9 | - Google App Script / GAS / javascript 10 | 11 | +-------+-------+-----------+------+ 12 | | name | job | role | num | 13 | +-------+-------+-----------+------+ 14 | | bob | Sales | Primary | 10.0 | 15 | | sally | IT | Primary | -2.0 | 16 | | john | HR | Secondary | 15.5 | 17 | +-------+-------+-----------+------+ 18 | 19 | var name = source_sheet.getRange("A:A").getValues(); 20 | // ["name","bob","sally","john"] 21 | var job = source_sheet.getRange("B:B").getValues(); 22 | // ["job","Sales","IT","HR"] 23 | var num = source_sheet.getRange("D:D").getValues(); 24 | // ["num",10.0,-2.0,15.5] 25 | 26 | 27 | Usage: 28 | var copyArray = ColumnTransposer_(name,job,num); 29 | target_Sheet.getRange(1,1,copyArray.length, copyArray[0].length).setValues(copyArray); 30 | */ 31 | 32 | function ColumnTransposer_() 33 | { 34 | var copyArray = []; //Create empty array 35 | for (var i=0, iL=arguments[0].length; i1) //if statement for multi-Column returns 145 | { 146 | newArray.push(Sending); 147 | if(CCL-1 == cc) //if statement for pulling all columns into larger array 148 | { 149 | twoDimensionalArray.push(newArray); 150 | var Found = 1; //Modifying found to 1 if found to stop all other logic in nn loop 151 | break; //Breaking cc loop once found 152 | } 153 | } 154 | else if (CCL<=1) //if statement for single-Column returns 155 | { 156 | twoDimensionalArray.push(Sending); 157 | var Found = 1; //Modifying found to 1 if found to stop all other logic in nn loop 158 | break; //Breaking cc loop once found 159 | } 160 | } 161 | } 162 | if(NNL-1==nn && isEmpty_(Sending)) //following if statement is for if the current item in lookup array is not found. Nessessary for data structure. 163 | { 164 | for(var na=0,NAL=IndexOffSetForReturn.length;na1) //checks to see if it's a Multi column return 172 | { 173 | var Sending = NALoad; 174 | newArray.push(Sending); 175 | } 176 | } 177 | if (NAL>1) //checks to see if it's a Multi column return 178 | { 179 | twoDimensionalArray.push(newArray); 180 | } 181 | } 182 | } 183 | } 184 | if(!/^return$/i.test(SetSheetRange)) 185 | { 186 | if (CCL<=1) //checks to see if it's a single column return for running setValue 187 | { 188 | var singleArrayForm = []; 189 | for (var l = 0,lL=twoDimensionalArray.length; l1) //checks to see if it's a multi column return for running setValues 196 | { 197 | SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,twoDimensionalArray.length,twoDimensionalArray[0].length).setValues(twoDimensionalArray); 198 | } 199 | if(/^y$/i.test(Add_Note)) 200 | { 201 | if(Object.prototype.toString.call(RefSheetRange) === '[object Array]') 202 | { 203 | SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,1,1).setNote("VLookup Script Ran On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a") + "\nRange: Origin Variable" ); 204 | } 205 | if(Object.prototype.toString.call(RefSheetRange) === '[object String]') 206 | { 207 | SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,1,1).setNote("VLookup Script Ran On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a") + "\nRange: " + RefSheetRange); 208 | } 209 | } 210 | SpreadsheetApp.flush(); 211 | SpreadsheetApp.getActiveSpreadsheet().toast('At: '+SetSheetRange,'Lookup Completed:'); 212 | } 213 | if(/^return$/i.test(SetSheetRange)) 214 | { 215 | return twoDimensionalArray 216 | } 217 | } 218 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 219 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GAS-Helper-Function 2 | Google App Script Helper Functions. 3 | JavaScript I have found useful or wrote myself to assisnt myself in project management spreadsheets. 4 | 5 | Some of them are dependant on each other. 6 | In general usage I add all of them to a singular .gs script file to the given project. 7 | -------------------------------------------------------------------------------- /SumColArray_.js: -------------------------------------------------------------------------------- 1 | 2 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 3 | //--//Dependent on cleanArray_() 4 | // Array Col Sum Agent 5 | function SumColArray_(sumagent) 6 | { 7 | var newArray = new Array(); 8 | for(var i = 0, sL = sumagent.length; i= 1000) 18 | { 19 | var PadWhseNum = pad_(IncomingWhseNum,5); 20 | } 21 | for(var w=0, wL = WhseEmails.length; w= 1){items[LoopDupCheck] = 1+items[LoopDupCheck];continue;} 41 | if (items[LoopDupCheck] == -1) 42 | { 43 | duplicates.push([LoopDupCheck]); 44 | items[LoopDupCheck] = 2; 45 | continue; 46 | } 47 | items[LoopDupCheck] = -1 48 | } 49 | var output = {array:duplicates,dupCountsObj:items} 50 | return output 51 | } 52 | 53 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 54 | -------------------------------------------------------------------------------- /elimDupsInArray_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | //Elimnates Duplicates in one or two dimensional array 3 | function elimDupsInArray_(arr) 4 | { 5 | if(!Array.isArray(arr)) 6 | { 7 | Logger.log("Inbound Parameter 'arr' is not an Array. Returning"); 8 | return 9 | } 10 | var out=[]; 11 | var obj={}; 12 | for (var i=0, vL=arr.length; i= 0) 34 | { 35 | var ssOpen = SpreadsheetApp.openByUrl(Destination_key) 36 | } 37 | if(DestTypeCheck == -1) 38 | { 39 | var ssOpen = SpreadsheetApp.openById(Destination_key) 40 | } 41 | } 42 | catch(e) 43 | { 44 | Logger.log(e) 45 | return 46 | } 47 | 48 | testOrCreateSheet_(Destination_Sheet,Destination_key); 49 | 50 | var Destination_RowVal = ssOpen.getSheetByName(Destination_Sheet).getRange(Destination_Range).getRow(); 51 | var Destination_ColVal = ssOpen.getSheetByName(Destination_Sheet).getRange(Destination_Range).getColumn(); 52 | 53 | ssOpen.getSheetByName(Destination_Sheet).getRange(Destination_RowVal,Destination_ColVal,Source_Load.length,Source_Load[0].length).setValues(Source_Load); 54 | if(Add_Note.toUpperCase() == 'Y') 55 | { 56 | var Source_Key = SpreadsheetApp.getActiveSpreadsheet().getId(); 57 | var Source_Name = SpreadsheetApp.getActiveSpreadsheet().getName(); 58 | 59 | ssOpen.getSheetByName(Destination_Sheet).getRange(Destination_RowVal,Destination_ColVal,1,1).setNote("Export Script Updated On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a")+"\nSS Name: "+Source_Name+"\nRange: "+Source_Sheet+"!"+Source_Range+"\nSS Key: "+ Source_Key); 60 | } 61 | SpreadsheetApp.flush(); 62 | SpreadsheetApp.getActiveSpreadsheet().toast('At: '+Source_SheetRange,'Export Completed to: '+ ssOpen.getName()); 63 | } 64 | -------------------------------------------------------------------------------- /frenchDate_.js: -------------------------------------------------------------------------------- 1 | 2 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 3 | function frenchDate_(date) 4 | { 5 | if ( Object.prototype.toString.call(date) === "[object Date]" ) 6 | { //date it is a date object 7 | if ( isNaN( date.getTime() ) ) 8 | { // d.valueOf() could also work 9 | Logger.log('Inbound date error #1: ' + date); // date is not valid 10 | return 11 | } 12 | else 13 | { 14 | var month = ['janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre']; 15 | var day = ['dimanche','lundi','mardi','mercredi','jeudi','vendredi','samedi']; 16 | var m = month[date.getMonth()]; 17 | var d = day[date.getDay()]; 18 | var dateStringFr = d+' '+date.getDate()+' '+m+' '+date.getFullYear(); 19 | return dateStringFr 20 | } 21 | } 22 | else 23 | { 24 | Logger.log('inbound date error #2: ' + date); 25 | return 26 | } 27 | } 28 | 29 | /* 30 | you want to use the following format: 31 | 32 | le xxxxx 15 cccc 2015. 33 | 34 | replace xxxxx with days (no capitals for weekdays in french) 35 | 36 | Monday = lundi 37 | Tuesday = mardi 38 | Wednesday = mercredi 39 | Thursday = jeudi 40 | Friday = vendredi 41 | Saturday = samedi 42 | Sunday = dimanche 43 | 44 | replace cccc with the month ( again, no capital ) 45 | January = janvier 46 | February = février 47 | March = mars 48 | April = avril 49 | May = mai 50 | June = juin 51 | July = juillet 52 | August = août 53 | September = septembr 54 | October = octobre 55 | November = novembre 56 | December = décembre 57 | */ 58 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 59 | 60 | -------------------------------------------------------------------------------- /gco_.js: -------------------------------------------------------------------------------- 1 | 2 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 3 | //Returns the offset value of the column (Row 1) titled "Status" 4 | //(eg, if the 7th column is labeled "Status", this function returns 6) 5 | // 6 | // Usage: gco_("dogs",sheet) 7 | // Output: 1 8 | // 9 | // Usage: gco_("Chickens",sheet,1) 10 | // Output: 3 11 | // 12 | /* 13 | | Cats | Dogs | Farm Animals | 14 | | | | Cows | Chickens | 15 | */ 16 | //retired function name "getColumnOffsetOfCurrentParameter_()" and shortened to "gco_()" 17 | function gco_(ColumnHeader,sheet,Row) 18 | { 19 | Row = typeof Row !== 'undefined' ? Row : 0; //Pre-Defined Row 1 as the title line if user does not load the second parameter with a Row Number call. 20 | var lastColumn = sheet.getLastColumn(); 21 | var range = sheet.getRange(1,1,1,lastColumn); 22 | var HeaderObj = {}; 23 | if(Object.prototype.toString.call(ColumnHeader) === '[object Array]') 24 | { 25 | for(var j = 0,JL = ColumnHeader.length; j < JL ; j++) 26 | { 27 | var Found = 0; 28 | var CurrentHeader = ColumnHeader[j]; 29 | for(var i = 0,IL = range.getLastColumn(); i < IL ; i++) 30 | { 31 | if (range.offset(Row, i, 1, 1).getValue() == CurrentHeader) 32 | { 33 | var Found = 1; 34 | HeaderObj[CurrentHeader] = i; 35 | } 36 | } 37 | if(Found == 0) 38 | { 39 | Logger.log('Column Title: "' + ColumnHeader + '" — Was not found on: ' + sheet.getName()); 40 | } 41 | } 42 | return HeaderObj 43 | } 44 | 45 | if(Object.prototype.toString.call(ColumnHeader) === '[object String]') 46 | { 47 | var Found = 0; 48 | for (var i = 0,IL = range.getLastColumn(); i < IL ; i++) 49 | { 50 | if (range.offset(Row, i, 1, 1).getValue() == ColumnHeader) 51 | { 52 | var Found = 1; 53 | return i; 54 | } 55 | } 56 | if(Found == 0) 57 | { 58 | Logger.log('Column Title: "' + ColumnHeader + '" — Was not found on: ' + sheet.getName()); 59 | } 60 | } 61 | } 62 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 63 | -------------------------------------------------------------------------------- /getFirstEmptyRowUsingArray_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | //--//Dependent on isEmpty_() 3 | //Find Last Row on Database 4 | function getFirstEmptyRowUsingArray_(sheetname) 5 | { 6 | var data = SpreadsheetApp.getActive().getSheetByName(sheetname).getDataRange().getValues(); 7 | for(var n = data.length ; n>0 ; n--) 8 | { 9 | if(isEmpty_(data[n])==false) 10 | { 11 | n++; 12 | break; 13 | } 14 | } 15 | n++; 16 | return (n); 17 | } 18 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 19 | -------------------------------------------------------------------------------- /importRange_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | //--//Dependent on testOrCreateSheet_() 3 | //Script Based ImportRange 4 | 5 | //Example importRange_('0AodPsggrbsh1dDNH....................','Main4NS!A:G','Common!C7','y') 6 | //Example importRange_('0AodPsggrbsh1dDNH....................','Main4NS!A:G','return','y') 7 | //Explanation importRange_('Importing Spreadsheet Key or URL','Importing Spreadsheet Tab Name and Range','Destination Spreadsheet Tab Name and Range or Return to variable','Will add note to the first cell of import') 8 | 9 | function importRange_(Source_Key,Source_SheetRange,SetSheetRange,Add_Note) 10 | { 11 | var SourceTypeCheck = Source_Key.indexOf("https://"); 12 | 13 | var Source_SheetRangeArr = Source_SheetRange.split("!"); 14 | var Source_Sheet = Source_SheetRangeArr[0]; 15 | var Source_Range = Source_SheetRangeArr[1]; 16 | if(SourceTypeCheck >= 0) 17 | { 18 | var Load = SpreadsheetApp.openByUrl(Source_Key).getSheetByName(Source_Sheet).getRange(Source_Range).getValues(); 19 | var Name = SpreadsheetApp.openByUrl(Source_Key).getName(); 20 | } 21 | if(SourceTypeCheck == -1) 22 | { 23 | var Load = SpreadsheetApp.openById(Source_Key).getSheetByName(Source_Sheet).getRange(Source_Range).getValues(); 24 | var Name = SpreadsheetApp.openById(Source_Key).getName(); 25 | } 26 | 27 | if(!/^return$/i.test(SetSheetRange)) 28 | { 29 | var SetSheetRangeArr = SetSheetRange.split("!"); 30 | var Set_Sheet = SetSheetRangeArr[0]; 31 | var Set_Range = SetSheetRangeArr[1]; 32 | testOrCreateSheet_(Set_Sheet); //testOrCreateSheet_() will autohide if the sheet does not exist already. due to my liking of quick clean spreadsheet magic. 33 | var RowVal = SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(Set_Range).getRow(); 34 | var ColVal = SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(Set_Range).getColumn(); 35 | SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,Load.length,Load[0].length).setValues(Load); 36 | if(Add_Note.toUpperCase() == 'Y') 37 | { 38 | SpreadsheetApp.getActive().getSheetByName(Set_Sheet).getRange(RowVal,ColVal,1,1).setNote("Import Script Updated On: " + Utilities.formatDate(new Date(), "PST", "MM-dd-yyyy hh:mm a")+"\nSS Name: "+Name+"\nRange: "+Source_Sheet+"!"+Source_Range+"\nSS Key: "+ Source_Key); 39 | } 40 | SpreadsheetApp.flush(); 41 | SpreadsheetApp.getActiveSpreadsheet().toast('At: '+SetSheetRange,'Import Completed:'); 42 | } 43 | if(/^return$/i.test(SetSheetRange)) 44 | { 45 | return Load; 46 | } 47 | 48 | 49 | } 50 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 51 | 52 | -------------------------------------------------------------------------------- /isDate_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | function isDate_(date,logs) 3 | { 4 | var logs = typeof logs !== 'undefined' ? logs : ""; 5 | if ( Object.prototype.toString.call(date) === "[object Date]" ) 6 | { //date it is a date object 7 | if(logs=="x"){Logger.log('isDate:1-' + date);} 8 | if ( isNaN( date.getTime() ) ) 9 | { // d.valueOf() could also work 10 | if(logs=="x"){Logger.log('isDate:2-' + date);} // date is not valid 11 | return false 12 | } 13 | else 14 | { 15 | return true 16 | } 17 | } 18 | else 19 | { 20 | if(logs=="x"){Logger.log('isDate:3-' + date);} 21 | return false 22 | } 23 | } 24 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 25 | -------------------------------------------------------------------------------- /isEmpty_.js: -------------------------------------------------------------------------------- 1 | 2 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 3 | // Empty String Check 4 | function isEmpty_(string) 5 | { 6 | if(Object.prototype.toString.call(string) === '[object Boolean]') return false; 7 | 8 | if(!string) return true; 9 | if(string == '') return true; 10 | if(string === false) return true; 11 | if(string === null) return true; 12 | if(string == undefined) return true; 13 | string = string+' '; // check for a bunch of whitespace 14 | if('' == (string.replace(/^\s\s*/, '').replace(/\s\s*$/, ''))) return true; 15 | 16 | return false; 17 | } 18 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 19 | 20 | -------------------------------------------------------------------------------- /isEven_.js: -------------------------------------------------------------------------------- 1 | 2 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 3 | // Even/Odd 4 | function isEven_(value) { 5 | if (value%2 == 0) 6 | return true; 7 | else 8 | return false; 9 | } 10 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 11 | 12 | -------------------------------------------------------------------------------- /moneyMath_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | // Takes a numeric value and turns into a string with periods, commas, and dollar sign. 3 | function moneyMath_(incomingMoney) 4 | { 5 | //--- 6 | Number.prototype.formatMoney = function(c, d, t){ 7 | var n = this, 8 | c = isNaN(c = Math.abs(c)) ? 2 : c, 9 | d = d == undefined ? "." : d, 10 | t = t == undefined ? "," : t, 11 | s = n < 0 ? "-" : "", 12 | i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", 13 | j = (j = i.length) > 3 ? j % 3 : 0; 14 | return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); 15 | }; 16 | //--- 17 | 18 | return "$" + incomingMoney.formatMoney(2); 19 | } 20 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 21 | -------------------------------------------------------------------------------- /objToString_.js: -------------------------------------------------------------------------------- 1 | function objToString_(obj) { 2 | var str = ''; 3 | for (var p in obj) { 4 | if (obj.hasOwnProperty(p)) { 5 | str += p + ':' + obj[p] + '\n'; 6 | } 7 | } 8 | return str; 9 | } 10 | -------------------------------------------------------------------------------- /objectify_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | function objectify_(array) 3 | { 4 | // incoming Array: var array = [ [1,'a'], [2,'b'], [3,'c'] ]; 5 | // Output Object: { 1: "a", 2: "b", 3: "c" }; 6 | // Note pull only 2 columns into the array. will add code to expect that later. 7 | return array.reduce(function(p, c) { 8 | p[c[0]] = c[1]; 9 | return p; 10 | }, {}); 11 | } 12 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 13 | -------------------------------------------------------------------------------- /pad_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | // Pad a number with x amound of Zero 3 | 4 | //example 'var PadWhseNum = pad_(IncomingWhseNum,5);' 5 | //output would for "15" would be "00015" 6 | 7 | function pad_(n, width, z) 8 | { 9 | z = z || '0'; 10 | n = n + ''; 11 | return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; 12 | } 13 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 14 | -------------------------------------------------------------------------------- /pauseComp_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | //Stops script for x amount of milliseconds 3 | function pauseComp_(millis) 4 | { 5 | var date = new Date(); 6 | var curDate = null; 7 | do { curDate = new Date(); } 8 | while(curDate-date < millis); 9 | } 10 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 11 | -------------------------------------------------------------------------------- /queryNegetive_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | // Checker for AS400 DB Showcase-query output for negative numbers 3 | // Thanks Stephen Ewell for writing this one. 4 | function queryNegetive_(value) { 5 | 6 | var pattern = /(^\d{1,})?(.)?(\d{1,})?(-)/ 7 | var output = value.toString(); 8 | check = output.match(pattern); 9 | if (check != null) { 10 | var a; 11 | if (check[1] != null) { 12 | a = check[1]; 13 | } else if (check[2] != null && check[3] != null) { 14 | a = "0"; 15 | } 16 | if (check[2] != null && check[3] != null) { 17 | a += check[2] + check[3]; 18 | } 19 | a = 0.0 - Number(a) 20 | return Number(a); 21 | } 22 | 23 | return Number(value); 24 | } 25 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 26 | 27 | -------------------------------------------------------------------------------- /setRowColors_.js: -------------------------------------------------------------------------------- 1 | 2 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 3 | //--//Dependent on getColumnOffsetOfCurrentParameter_() 4 | //Script version to conditional Formatting. 5 | //e.g. 'setRowColors_('Status',0);' 6 | function setRowColors_(TargetColumnHeaderContent,TargetRowForHeader) 7 | { 8 | var sheet = SpreadsheetApp.getActiveSheet(); 9 | var range = SpreadsheetApp.getActiveSheet().getDataRange(); 10 | var TargetColumnOffset = getColumnOffsetOfCurrentParameter_(TargetColumnHeaderContent,sheet); 11 | if (typeof TargetColumnOffset === 'undefined') 12 | { 13 | Logger.log("Column Header not found"); 14 | return 15 | } 16 | for (var i = range.getRow(); i < range.getLastRow(); i++) 17 | { 18 | var rowRange = range.offset(i, 0, 1); 19 | var status = rowRange.offset(0, TargetColumnOffset).getValue(); 20 | if (status == 'Completed') 21 | { 22 | rowRange.setBackgroundColor("#DEAD01"); //goldenRod 23 | } 24 | else if (status == 'In Progress') 25 | { 26 | rowRange.setBackgroundColor("#FFDD88"); //Dim Yellow 27 | } 28 | else if (status == 'Not Started') 29 | { 30 | rowRange.setBackgroundColor("#CC6666"); //maroon 31 | } 32 | } 33 | } 34 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 35 | -------------------------------------------------------------------------------- /subDaysFromDate_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | // Subtract Days from Date Function 3 | // Thanks Sean Dalhover for finding this golden nugget!!! 4 | // if 'TimeFrame' is 7/20/2016 from 'var TimeFrame = col[0];' in a loop and you want to email someone 10 days before that date you would: 5 | // subDaysFromDate_(TimeFrame,'10') 6 | // would return 7/10/2016 7 | 8 | function subDaysFromDate_(date,d,logs) 9 | { 10 | var logs = typeof logs !== 'undefined' ? logs : ""; 11 | if ( Object.prototype.toString.call(date) === "[object Date]" ) 12 | { //date it is a date object 13 | if(logs=="x"){Logger.log('subDaysFromDate:1-' + date);} 14 | if ( isNaN( date.getTime() ) ) 15 | { // d.valueOf() could also work 16 | if(logs=="x"){Logger.log('subDaysFromDate:2-' + date);} // date is not valid 17 | return 18 | } 19 | else 20 | { 21 | var dateToAlter = date; 22 | var result = new Date(dateToAlter.getTime()-d*(24*3600*1000)); 23 | return result 24 | } 25 | } 26 | else 27 | { 28 | if(logs=="x"){Logger.log('subDaysFromDate:3-' + date);} 29 | return 30 | } 31 | } 32 | 33 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 34 | -------------------------------------------------------------------------------- /testOrCreateSheet_.js: -------------------------------------------------------------------------------- 1 | function testOrCreateSheet_(TargetSheetName,TargetWorkbook) 2 | { 3 | var TargetWorkbook = typeof TargetWorkbook !== 'undefined' ? TargetWorkbook : ""; 4 | 5 | try 6 | { 7 | if(TargetWorkbook == "") 8 | { 9 | var ssOpen = SpreadsheetApp.getActive(); 10 | } 11 | if(TargetWorkbook != "") 12 | { 13 | var DestTypeCheck = TargetWorkbook.indexOf("https://"); 14 | if(DestTypeCheck >= 0) 15 | { 16 | var ssOpen = SpreadsheetApp.openByUrl(TargetWorkbook) 17 | } 18 | if(DestTypeCheck == -1) 19 | { 20 | var ssOpen = SpreadsheetApp.openById(TargetWorkbook) 21 | } 22 | } 23 | } 24 | catch(e) 25 | { 26 | Logger.log(e) 27 | return 28 | } 29 | var Sheet = ssOpen.getSheetByName(TargetSheetName); 30 | if (Sheet == null) 31 | { 32 | var Sheet = ssOpen.insertSheet().setName(TargetSheetName); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /uniDateTime_.js: -------------------------------------------------------------------------------- 1 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 2 | function uniDateTime_(InDate,TimeFormats,logs) 3 | { 4 | var InDate = typeof InDate !== 'undefined' ? InDate : "" 5 | var TimeFormats = typeof TimeFormats !== 'undefined' ? TimeFormats : "" 6 | var logs = typeof logs !== 'undefined' ? logs : ""; 7 | if (InDate == "") 8 | { 9 | if (TimeFormats == "") 10 | { 11 | return new Date(); 12 | } 13 | else 14 | { 15 | var result = Utilities.formatDate(new Date(), "PST", TimeFormats); 16 | return result; 17 | } 18 | } 19 | if (Object.prototype.toString.call(InDate) === "[object Date]" ) 20 | { //date it is a date object 21 | if(logs=="x"){Logger.log('UniDate:1-' + InDate);} 22 | if ( isNaN( InDate.getTime() ) ) 23 | { // d.valueOf() could also work 24 | if(logs=="x"){Logger.log('UniDate:2-' + InDate);} // date is not valid 25 | return; 26 | } 27 | else 28 | { 29 | var result = Utilities.formatDate(new Date(InDate), "PST", TimeFormats); 30 | return result; 31 | } 32 | } 33 | else 34 | { 35 | if(logs=="x"){Logger.log('UniDate:3-' + InDate);} 36 | return; 37 | } 38 | } 39 | //~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~`~,~` 40 | 41 | --------------------------------------------------------------------------------