Skip to content

Instantly share code, notes, and snippets.

@rascode
Created December 2, 2016 01:01
Show Gist options
  • Save rascode/949aaaba1520e0d11cc1c84e831636db to your computer and use it in GitHub Desktop.
Save rascode/949aaaba1520e0d11cc1c84e831636db to your computer and use it in GitHub Desktop.
Google Apps Script Library
//Access the Spreadsheet - Declare globally
var ssid = ScriptProperties.getProperty('ssid'); //Spreadsheet ID. Value has been stored as a property
var ss = SpreadsheetApp.openById(ssid); //Opens the Spreadsheet using the stored property Spreadsheet ID
//Create variables for known sheets and all sheets
var iosSheet = getValueOfSheetByName("iOS"); //The iOS sheet
var gasSheet = getValueOfSheetByName("GAS"); //The Google Apps Script sheet
var allSheets = getValueOfAllSheets(); //All Sheet Values
//Return Data for all Sheets
function getValueOfAllSheets(sheetID) {
return ss.getDataRange().getValues();
}
//Function that accepts that sheet name as a parameter and returns the sheet data
function getValueOfSheetByName(sheetID) {
return ss.getSheetByName(sheetID).getDataRange().getValues();
}
//Create a get request for the data of a specific sheet
function doGet(request) {
var callback = request.parameters.jsonp;
var range = gasSheet;
var json = callback + '(' + Utilities.jsonStringify(range) + ')';
var requestData = ContentService.createTextOutput(json).setMimeType(ContentService.MimeType.JSON);
return requestData;
}
/**
* Retrieves a given user label by name and logs the number of unread threads
* associated with that that label.
* For more information on interacting with GMail labels, see
* https://developers.google.com/apps-script/class_gmaillabel
*/
function processLabel(labelName) {
// get the label for given name
var label = GmailApp.getUserLabelByName(labelName);
var threads = label.getThreads();
// get count of all threads in the given label
var threadCount = label.getUnreadCount();
Logger.log(threadCount);
};
processLabel("[Mailbox]\Action")
function getEmailsByLabel(){
var action = GmailApp.search('label:[mailbox]-action');
//Define the Template
var template = HtmlService.createTemplateFromFile('template');
//make Variables / data available for use within the template
//e.g. the variable <?= action ?> used inside the template will now be defined as the variable "action" specified above
template.action = action;
//Create a variable called 'emailContent' to hold the hmtl of the 'template.html' file
var emailContent = template.evaluate().getContent();
//pass 'html' as an option to the GmailApp service so the email will be rendered as
var options = {
htmlBody: emailContent,
}
GmailApp.sendEmail("[email protected]", "Your Action Items", emailContent, options);
}
//Declared Property Values
var adminEmail = ScriptProperties.getProperty('admin_email');
//Spreadsheet Variables
var ssid = ScriptProperties.getProperty('ssid');
var ss = SpreadsheetApp.openById(ssid);
var sheet = ss.getSheets()[0];
var numSheetsInSpreadsheet = ss.getNumSheets();
var dataInSheet = ss.getDataRange().getValues();
//Range Row 1 Values
var range = ss.getDataRange();
var rangeData = range.getValues();
//Spreadsheet Row 1 Values
var rows = range.getRow();
var numRows = range.getNumRows();
//Document Count
var numOfFolders =  DocsList.getAllFolders().length;
var numOfDocs = DocsList.getAllFiles().length;
//Function that fires when spreadsheet is opened
function onOpen(e){
var ss = SpreadsheetApp.getActiveSpreadsheet();
Browser.msgBox("Hey, I'm opened");
//Logger.log("Hey, you opened me up");
}
function getSheetNames(sheetid){
var numOfSheetsInSpreadsheet = ss.getSheets().length;
var sheetsInSheet = ss.getSheets();
var allSheetNames = [];
//Logs - To be removed in Production Environment
Logger.log("You have " + numOfFolders + " folders and " + numOfDocs + " documents") ;
Logger.log("There are a total of "+ numOfSheetsInSpreadsheet + " sheets and they are named: ");
for (i in sheetsInSheet){
//Create an Array of the sheet names
allSheetNames.push(currentSheetInSpreadsheet_Name);
//Create Variables for the Name, Index and Values of each Sheet in the Spreadsheet
var currentSheetInSpreadsheet_Name = sheetsInSheet[i].getName();
var currentSheetInSpreadsheet_ID = sheetsInSheet[i].getIndex();
var currentSheetInSpreadsheet_Data = sheetsInSheet[i].getDataRange().getValues();
}
Logger.log(allSheetNames);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment