Skip to content

Instantly share code, notes, and snippets.

@aplater
aplater / parse-csv-email.js
Created September 27, 2019 18:01 — forked from siygle/parse-csv-email.js
Parse CSV, filter and then output to another file (e.g, Email)
const parse = require('csv-parse')
const fs = require('fs')
const transform = require('stream-transform')
const isEmail = require('is-email')
const input = fs.createReadStream('./input.csv')
const output = fs.createWriteStream('./output.csv')
const parser = parse({ delimiter: ',' })
const transformer = transform((record, callback) => {
@aplater
aplater / 70e04a67f1f5fd96a708.md
Created September 27, 2019 18:06 — forked from oshliaer/70e04a67f1f5fd96a708.md
Extract Gmail content to a spreadsheet #gas #gmail #sheet
@aplater
aplater / SendDocument.js
Created September 27, 2019 18:21 — forked from erickoledadevrel/SendDocument.js
Send a Google Doc in an email using Apps Script
/**
* Sends an email using the contents of a Google Document as the body.
*/
function sendDocument(documentId, recipient, subject) {
var html = convertToHtml(documentId);
html = inlineCss(html);
GmailApp.sendEmail(recipient, subject, null, {
htmlBody: html
});
}
@aplater
aplater / imageToText.gs
Created January 15, 2020 13:49 — forked from tagplus5/imageToText.gs
google apps script image to text ocr
function doGet(request) {
if (request.parameters.url != undefined && request.parameters.url != "") {
var imageBlob = UrlFetchApp.fetch(request.parameters.url).getBlob();
var resource = {
title: imageBlob.getName(),
mimeType: imageBlob.getContentType()
};
var options = {
ocr: true
};
@aplater
aplater / Google Apps Script Survey Workflow.md
Created February 6, 2020 19:41 — forked from mogsdad/Google Apps Script Survey Workflow.md
Google Apps Script workflow for an email survey. Written in response to StackOverflow question 18668828. http://stackoverflow.com/a/18669532/1677912

Google Apps Script Survey Workflow

The components involved in this workflow are:

  • A script to generate and send an email with an HTML form.
  • An html template for that email, which allows us to customize the email for each recipient.
  • A doPost() function to handle responses. The script must be [deployed as a Web App][1].
  • A spreadsheet to collect responses. The script will be contained in the spreadsheet, and extends the spreadsheet UI with a menu for sending a copy of the survey. (It could be adapted for standalone use, without the UI component.)

Here is an example of such a workflow, conducting a Commuting Survey. Recipients will receive a survey email like this:

@aplater
aplater / checkAndHide.gs
Created February 20, 2020 13:31 — forked from erickoledadevrel/checkAndHide.gs
Google Apps Script code to hide a row when a checkbox is checked.
/*
* Copyright 2019 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
var CHECKBOX_COLUMN = 'B';
function onEdit() {
var range = SpreadsheetApp.getActiveRange();
if (range.getA1Notation().split(/\d/)[0] == CHECKBOX_COLUMN &&
@aplater
aplater / downloadFileRange.gs
Created February 20, 2020 13:32 — forked from erickoledadevrel/downloadFileRange.gs
Downloading a portion of a Drive file in Apps Script.
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
}
function onOpen() {
DocumentApp.getUi().createMenu('Demo')
.addItem('Select Spreadsheet', 'selectSpreadsheet')
.addItem('Update Data', 'updateData')
.addToUi();
}
function selectSpreadsheet() {
var result = DocumentApp.getUi().prompt('Enter the ID of the spreadsheet:');
var spreadsheetId = result.getResponseText();
@aplater
aplater / Code.js
Created February 20, 2020 13:32 — forked from erickoledadevrel/Code.js
Remove multiple line breaks in a Googe Document using Apps Script
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)) {
@aplater
aplater / convertDocs2Html.js
Created February 20, 2020 13:34 — forked from soundTricker/convertDocs2Html.js
Convert Google Docs 2 Html on Google Apps Script GASでGoogle DocumentのファイルをHTMLに変換します。
var KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; //developer key , get from https://code.google.com/apis/console/b/1/
var FILE_ID = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; // drive file id
function convertDocuments2() {
var oauthConfig = UrlFetchApp.addOAuthService('drive');
//Create oauth config for drive api
var scope = 'https://www.googleapis.com/auth/drive';
oauthConfig.setConsumerKey('anonymous');
oauthConfig.setConsumerSecret('anonymous');