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
(function() { | |
// Include jQuery. | |
var script = document.createElement('script'); | |
script.src = 'https://code.jquery.com/jquery-2.1.1.min.js'; | |
script.type = 'text/javascript'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
var sections = [ | |
'Default MIME Types', | |
'Default File Extensions', |
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
<html> | |
<head> | |
<title>GAM Sample App</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.17.1/URI.js"></script> | |
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script> | |
</head> | |
<body> | |
<h1>GAM Sample App</h1> | |
<p id="message">Loading...</p> | |
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
function publish() { | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = spreadsheet.getSheetByName('Announcements'); | |
var data = sheet.getDataRange().getValues(); | |
var site = SitesApp.getSite('erickoledauniversity'); | |
var page = site.getChildByName('announcements'); | |
for (var i = 0; i < data.length; i++) { | |
var row = data[i]; | |
var title = row[1]; | |
var description = row[2]; |
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
function onOpen() { | |
SpreadsheetApp.getUi().createMenu('Testing') | |
.addItem('Show Sidebar', 'showSidebar') | |
.addToUi(); | |
} | |
function showSidebar() { | |
var sidebar = HtmlService.createHtmlOutputFromFile('Sidebar') | |
.setSandboxMode(HtmlService.SandboxMode.IFRAME) | |
.setTitle('Sidebar'); |
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
function downloadFileRange(fileId, startByte, endByte) { | |
// Mention DriveApp in a comment to ensure the Drive scope is requested. | |
// DriveApp.getRootFolder(); | |
var url = 'https://www.googleapis.com/drive/v3/files/' + | |
fileId + '?alt=media'; | |
var response = UrlFetchApp.fetch(url, { | |
headers: { | |
Authorization: 'Bearer ' + ScriptApp.getOAuthToken(), | |
Range: 'bytes=' + startByte + '-' + endByte | |
} |
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
function removeMultipleLineBreaks(element) { | |
if (!element) { | |
element = DocumentApp.getActiveDocument().getBody(); | |
} | |
var parent = element.getParent(); | |
// Remove empty paragraphs | |
if (element.getType() == DocumentApp.ElementType.PARAGRAPH | |
&& element.asParagraph().getText().replace(/\s/g, '') == '') { | |
if (!(parent.getType() == DocumentApp.ElementType.BODY_SECTION | |
&& parent.getChildIndex(element) == parent.getNumChildren() - 1)) { |
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
// Setup: Spreadsheet in Pacific time, Script in Eastern time, Calendar in Mountain time. | |
// Sample spreadsheet: https://docs.google.com/spreadsheets/d/1neePK1YPKMKnVwI8dld0HSJjI1kSFPpcY8g7kG8xG4U/edit#gid=0 | |
// A2 = 3/1/2016 9:00 AM, B2 = 3/1/2016 10:00 AM | |
/** | |
* The dates and times in the spreadsheet refer to exact moments in time, and the clock | |
* on the wall may show a different time. | |
*/ | |
function copyMoment() { | |
var ss = SpreadsheetApp.getActive(); |
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
function createTrigger() { | |
var time = new Date(); | |
time.setMinutes(time.getMinutes() + 5); | |
ScriptApp.newTrigger('run') | |
.timeBased() | |
.at(time) | |
.create(); | |
} | |
function run() { |
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
/** | |
* @license | |
* Copyright 2019 Google LLC | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* https://www.apache.org/licenses/LICENSE-2.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
function createEventWithAttachment() { | |
var driveFileId = '...'; | |
var file = DriveApp.getFileById(driveFileId); | |
var event = { | |
summary: 'Test Event with Attachments', | |
description: 'Woot!', | |
attachments: [{ | |
fileId: driveFileId, | |
fileUrl: file.getUrl(), | |
mimeType: file.getMimeType(), |
OlderNewer