Skip to content

Instantly share code, notes, and snippets.

@aplater
aplater / appsScript_ListFilesFolders_ver.2.js
Created January 29, 2021 19:01 — forked from mesgarpour/appsScript_ListFilesFolders_ver.2.js
[Google Apps Script] List all files & folders in a Google Drive folder, & write into a speadsheet
/*
* Copyright 2017 Mohsen Mesgarpour
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@aplater
aplater / google-apps-script.md
Created January 25, 2021 18:42 — forked from labnol/google-apps-script.md
How to Learn Google Apps Script

Learning Google Apps Script

Find the best resources for learning Google Apps Script, the glue that connects all GSuite services including Gmail, Google Drive, Calendar, Google Sheets, Forms, Maps, Analytics and more.

A good place to learn more about Google Apps Script is the official documentation available at developers.google.com. Here are other Apps Script resources that will help you get up to speed.

  1. Google Apps Script Code Samples by Amit Agarwal
  2. Google Apps Script Development - Create Google Apps Script projects locally inside VS Code - video tutorial
  3. Awesome Google Scripts by Amit Agarwal
  4. Google Developer Experts - Follow Apps Scr
@aplater
aplater / csv_import_magic.js
Created September 2, 2020 07:20 — forked from ianlewis/csv_import_magic.js
A Google Apps Script for importing CSV data into a Google Spreadsheet.
// vim: ft=javascript:
/*jslint sloppy: true, vars: true, white: true, nomen: true, browser: true */
/*global SpreadsheetApp, UiApp, UrlFetchApp, Utilities */
/*
* A script to automate requesting data from an external url that outputs CSV data.
*
* Adapted from the Google Analytics Report Automation (magic) script.
* @author [email protected] (Nick Mihailovski)
* @author [email protected] (Ian Lewis)
*/
@aplater
aplater / batch_ocr.gs
Created July 31, 2020 02:49 — forked from rob0tca/batch_ocr.gs
Google Apps script for performing OCR on all JPEGS found in the specified Drive folder. Extracts text to a Google sheet, where it's mapped to the JPEG's filename.
function extractTextOnOpen() {
//ADD YOUR VALUES BELOW
var folderName = "[YOUR PROJECT FOLDER]";
var sheetId = "[YOUR SHEET ID]";
//Define folder
var folder = DriveApp.getFoldersByName(folderName).next();
var folderId = folder.getId();
@aplater
aplater / index.js
Created March 3, 2020 15:05 — forked from alexismp/index.js
Node.js 8 Cloud Function to write to a Google Sheets document
// Copyright 2018 Google LLC.
// SPDX-License-Identifier: Apache-2.0
const { google } = require("googleapis");
const { Storage } = require("@google-cloud/storage");
exports.csv2sheet = async (data, context) => {
var fileName = data.name;
// basic check that this is a *.csv file, etc...
if (!fileName.endsWith(".csv")) {
@aplater
aplater / messages.html
Created February 26, 2020 14:02 — forked from prasanthmj/messages.html
Parse and extract data from Gmail to Google Sheet. Read full article here: http://blog.gsmart.in/parse-and-extract-data-from-gmail-to-google-sheets/
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Message Display Test</title>
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body style="padding:3em;">
<h1>Messages</h1>
<ul>
@aplater
aplater / gist:79e316e9155c3da108d3e31c708a5bc8
Created February 20, 2020 13:34 — forked from mhawksey/gist:2252211
Google Apps Script to combine data from different sheets (used in http://mashe.hawksey.info/?p=13130)
function combineData(){
var doc = SpreadsheetApp.getActiveSpreadsheet();
var sheets = doc.getSheets(); // get all the sheets
var outSheet = doc.getSheetByName("combined"); // set where we want to write the results
for (i in sheets){ // loop across all the sheets
if (sheets[i].getSheetName().substring(0,9) == "followers"){ // if sheetname starts with 'follower' then
var target = sheets[i].getSheetName().substring(12); // extract users name for target column
var data = getRowsData(sheets[i]); // get extisting data from current sheet
for (j in data){
data[j]["target"] = target; // create a target column with the users name
@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');
@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)) {
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();