Skip to content

Instantly share code, notes, and snippets.

@meetpahul
meetpahul / addTimeStamp.js
Last active July 19, 2022 01:51
Use this code to add date in a specified column when a certain cell/range is edited.
// Use this script to add date in a specific column when a spcecific range/cell is edited in the same row.
// To run this script, you must also add an event-based trigger to be run on edit.
function addDate(e) {
// Open the Google Sheet file
var ss = SpreadsheetApp.getActiveSpreadsheet();
// Open the active sheet where you want to add the date
// Deletes sheets whose names contain the criteria string. Takes Spreadsheet URL and Criteria-string as arguments.
function cleanSheets(url, criteriaString){
var ss = SpreadsheetApp.openByUrl(url)
var sheets = ss.getSheets()
for (var i=0; i<sheets.length; i++){
var sheetName = sheets[i].getSheetName();
if (sheetName.indexOf(criteriaString)>-1) {ss.deleteSheet(sheets[i])}
}
};
// This function takes a two-dimensional array and returns a flattened one-dimensional array
function flattenArray(array){
var flatArray = []
for (var i = 0; i < array.length; i++) {
flatArray.push(array[i][0])
}
return flatArray
}
// Emails the whole sheet as PDF
function emailGoogleSpreadsheetAsPDF(url, email, subject, body) {
// All arguements are strings
var ss = SpreadsheetApp.openByUrl(url)
var blob = DriveApp.getFileById(ss.getId()).getAs('application/pdf');
blob.setName(ss.getName() + '.pdf');
// If allowed to send emails, send the email with the PDF attachment
if (MailApp.getRemainingDailyQuota() > 0)
GmailApp.sendEmail(email, subject, body, {
htmlBody: body,
@meetpahul
meetpahul / GoogleDriveTableOfContents.gs
Last active July 16, 2021 20:23
This code goes through all the folders, subfolders, files and creates a table of content for them.
/*
* Google Apps Script - List all files & folders in a Google Drive folder, & write into a speadsheet.
* - Main function 1: List all folders and subfolders
* - Main function 2: List all files, folders and subfolders
* - You will receive information like file name, location, size, sharing, access information
*/
/*
* - If this is your first project, open a blank Google Sheets, go to Tools, go to Script Editor, Paste the following code,
* - and run the 'List All' Function.
@meetpahul
meetpahul / emailSheet.gs
Created May 9, 2019 16:31
Email a specific sheet from google sheet as pdf
function emailSheet() {
var email = "email@email.com"; // Enter email here. You can add multiple emails by separating them with comma.
var ss = SpreadsheetApp.openByUrl("GoogleSheetURL");
var subject = "Subject";
var body = 'Enter the message here'
var url = "https://docs.google.com/spreadsheets/d/SS_ID/export?".replace("SS_ID", ss.getId());
var url_ext = 'exportFormat=pdf&format=pdf'
+ '&size=letter'
+ '&portrait=false'
+ '&fitw=true'
function getGradebooks() {
var response = ui.alert('Alert!', 'Do you understand that this will create new copies of gradebooks?', ui.ButtonSet.YES_NO);
if (response == ui.Button.YES) {
var response2 = ui.prompt('Verification', 'What is the password?', ui.ButtonSet.OK_CANCEL).getResponseText();
if (response2 === 'password') {
ui.alert('Magic is happening! Gradebooks are under construction.');
var DGsheet = SpreadsheetApp.openByUrl('url of dashboard').getSheetByName('Gradebooks').activate();
var urls = DGsheet.getRange('E2:E');
var icfile = DriveApp.getFileById('id of incharge template');
@meetpahul
meetpahul / imageToText.gs
Created January 18, 2019 00:33 — 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
};
@meetpahul
meetpahul / GoogleDriveIndex.js
Last active July 7, 2022 06:51
This script goes through all the files and folders and then makes an index or table of content with links.
/*
Google Apps Script - List all files & folders in a Google Drive folder, & write into a speadsheet.
- Main function 1: List all folders and subfolders
- Main function 2: List all files, folders and subfolders
- Customization: You can make a few tweaks to change it according to your need but this can be a good starting point.
*/
var folderId = ''
@meetpahul
meetpahul / ShowRows.js
Created January 13, 2019 17:14
This function will help you unhide all the rows and columns in Google Sheet that are hidden.
function ShowRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var lastRow = sheet.getLastRow();
for( i=1 ; i<=lastRow ; i++) {
{
sheet.showRows(i);
}
}
};