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
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) => { |
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
/** | |
* 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 | |
}); | |
} |
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 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 | |
}; |
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:
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
/* | |
* 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 && |
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 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(); |
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
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'); |
OlderNewer