Skip to content

Instantly share code, notes, and snippets.

@MauricioMoraes
MauricioMoraes / column_number_by_name.gs
Last active August 29, 2015 14:25
Google Apps Script for Spreadsheets - Gets the column number from a given sheet name and column name. The function assumes the column names are on the first row. The resulting column number is zero-based (Column A -> 0)
function columnNumberByName(sheetName, ColumnName) {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName(sheetName)
var firstRowRange = sheet.getRange(1, 1, 1, sheet.getMaxColumns());
var columnNames = firstRowRange.getValues()[0];
for (var columnNumber in columnNames) {
if (columnNames[columnNumber] == ColumnName) {
return parseInt(columnNumber);
@MauricioMoraes
MauricioMoraes / get_first_gmail_draft_attributes.gs
Last active August 29, 2015 14:25
Google Apps Script Function to get the first gmail draft from your account and output its attributes.
function getFirstGmailDraftAttributes() {
var draftThreads = GmailApp.search("in:drafts", 0, 1);
if (draftThreads.length === 0) {
Browser.msgBox("No drafts found.");
return
}
var draft = draftThreads[0].getMessages()[0];