0% found this document useful (0 votes)
36 views18 pages

G Script

The document contains various Google Apps Script functions for automating tasks in Google Sheets, Google Docs, Google Calendar, and Gmail. Functions include writing and reading data from sheets, sending emails, creating documents, and managing calendar events. It also covers data manipulation techniques like removing duplicates, formatting cells, and exporting data to different formats.

Uploaded by

skripdee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views18 pages

G Script

The document contains various Google Apps Script functions for automating tasks in Google Sheets, Google Docs, Google Calendar, and Gmail. Functions include writing and reading data from sheets, sending emails, creating documents, and managing calendar events. It also covers data manipulation techniques like removing duplicates, formatting cells, and exporting data to different formats.

Uploaded by

skripdee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

WritingDatatoaGoogleSheet function writeToSheet() { var sheet =

[Link]().getActiveSheet();
[Link]("A1").setValue("Hello, world!"); } Reading Data from a Google Sheet
function readFromSheet() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]("A1").getValue(); [Link](data); } Creating a New Google Doc function
createGoogleDoc() { var doc = [Link]('New Document');
[Link]().appendParagraph('This is a new document.'); } Sending an Email with
GmailApp function sendEmail() { [Link]('recipient@[Link]', 'Test
Email', 'Hello, this is a test email from Google Apps Script.'); } Adding an Event to Google
Calendar function addCalendarEvent() { var calendar = [Link]();
[Link]('New Event', new Date(), new Date()); } Fetching Data from an
External API function fetchDataFromAPI() { var response =
[Link]('[Link] [Link]([Link]()); }
Creating a Custom Menu in Google Sheets function onOpen() { var ui =
[Link](); [Link]('Custom Menu') .addItem('Say Hello',
'sayHello') .addToUi(); } function sayHello()
{ [Link]().getActiveSheet().getRange('B1').setValue('Hel
lo!'); } Using Google Sheets as a Database function logData() { var sheet =
[Link]().getActiveSheet(); var rowContents = ['John', 'Doe',
new Date()]; [Link](rowContents); } Updating Google Sheet Data Based on
Conditions function updateCells() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]('A1:A10'); var values = [Link](); for (var i = 0; i < [Link]; i+
+) { if (values[i][0] === 'Done') { [Link](i + 1, 2).setValue('Completed'); } } }
Formatting Cells in Google Sheets function formatCells() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]('B1:B5'); [Link]('yellow'); [Link]('bold'); }
Removing Duplicate Rows in Google Sheets function removeDuplicates() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); var newData = []; var unique = {}; for (var i = 0; i <
[Link]; i++) { var row = data[i]; var key = [Link]("-"); // Create a unique string key for
comparison if (!unique[key]) { unique[key] = true; [Link](row); } }
[Link](); // Clear the old data [Link](1, 1, [Link],
newData[0].length).setValues(newData); // Set new data } Inserting a Chart in Google
Sheets function insertChart() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]('A1:B10'); // Select data range for the chart var chart =
[Link]() .setChartType([Link]) .addRange(range) .setPosition(5,
5, 0, 0) .build(); [Link](chart); } Convert Spreadsheet Data to JSON function
convertSheetToJson() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); var keys = [Link](); // First row
as keys var json = []; for (var i = 0; i < [Link]; i++) { var row = {}; for (var j = 0; j <
[Link]; j++) { row[keys[j]] = values[i][j]; } [Link](row); }
[Link]([Link](json)); } Batch Update Google Sheet Cells function
batchUpdateCells() { var sheet = [Link]().getActiveSheet();
var rangeList = [Link](['A1', 'B2', 'C3']); // List of cell addresses
[Link]('Updated'); } Auto-Resize Columns in Google Sheets function
autoResizeColumns() { var sheet =
[Link]().getActiveSheet(); [Link](1,
[Link]()); // Auto-resize all columns } Find and Replace Text in Google Docs
function findAndReplaceText() { var doc = [Link](); var body =
[Link](); [Link]('oldText', 'newText'); } List All Files in Google Drive Folder
function listFilesInFolder() { var folderId = 'your-folder-id-here'; // Replace with your folder ID
var files = [Link](folderId).getFiles(); while ([Link]()) { var file =
[Link](); [Link]([Link]()); } } Create a New Google Drive Folder function
createNewFolder() { var newFolder = [Link]('New Folder');
[Link]('Folder created with ID: ' + [Link]()); } Send an Email with an
Attachment from Google Drive function sendEmailWithAttachment() { var file =
[Link]('your-file-id-here'); // Replace with your file ID
[Link]( 'recipient@[Link]', 'Email with Attachment', 'Please find the
attached file.', { attachments: [[Link]([Link])], // Change MimeType as needed
name: 'Automatic Emailer Script' } ); } Add Custom Footer to Google Doc function
addCustomFooter() { var doc = [Link](); var footer =
[Link](); // Add a footer if it doesn't exist var paragraph =
[Link]('Confidential Document- For Internal Use Only');
[Link]([Link]); } Archiving Emails
from Gmail function archiveReadEmails() { var threads = [Link](); for
(var i = 0; i < [Link]; i++) { if (threads[i].isUnread() === false)
{ threads[i].moveToArchive(); } } } Create a Document Copy with a New Name function
createDocumentCopy() { var originalDocId = 'original-doc-id'; // Replace with your original
document ID var originalDoc = [Link](originalDocId); var copy =
[Link]('New Document Copy'); [Link]('Copied document ID: ' +
[Link]()); } Inserting a New Row in Google Sheets After the Last Row with Data function
insertNewRow() { var sheet = [Link]().getActiveSheet();
var lastRow = [Link](); [Link](lastRow); [Link](lastRow
+ 1, 1).setValue('New Data'); } Retrieve and Log the Names of All Spreadsheets in Google
Drive function logAllSpreadsheets() { var files =
[Link](MimeType.GOOGLE_SHEETS); while ([Link]()) { var file =
[Link](); [Link]([Link]()); } } Add a Custom Status Column to Google Sheets
Based on Another Column's Values function addStatusColumn() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("A2:A"); // Assuming column A contains data to check var values =
[Link](); for (var i = 0; i < [Link]; i++) { if (values[i][0] === 'Completed')
{ [Link](i + 2, 2).setValue('Done'); } else { [Link](i + 2, 2).setValue('In
Progress'); } } } Automatically Color Code Rows in Google Sheets Based on Cell Value
function colorCodeRows() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Select all used cells var values = [Link](); for (var i = 0; i
< [Link]; i++) { var row = [Link](i + 1, 1, 1, [Link]()); if
(values[i][0] === 'High Priority') { [Link]('red'); } else if (values[i][0] === 'Medium
Priority') { [Link]('yellow'); } else if (values[i][0] === 'Low Priority')
{ [Link]('green'); } } } Create and Email a PDF from a Google Sheet function
emailSheetAsPDF() { var sheet = [Link](); var sheetId =
[Link]().getSheetId(); var url = '[Link] +
[Link]() + '/export?format=pdf&gid=' + sheetId; var options = { headers:
{ 'Authorization': 'Bearer ' + [Link]() } }; var response =
[Link](url, options); var blob = [Link]().setName([Link]() +
'.pdf'); [Link]('recipient@[Link]', 'Sheet PDF', 'Find the attached
PDF.', { attachments: [blob] }); } Update Google Calendar Events Based on Google Sheets
Data function updateCalendarEvents() { var sheet =
[Link]().getActiveSheet(); var dataRange =
[Link](); var data = [Link](); var calendar =
[Link]('your-calendar-id@[Link]'); // Replace with your
Calendar ID for (var i = 1; i < [Link]; i++) { // Starting from row 2 to skip headers var
eventId = data[i][0]; // Assuming the event ID is in the first column var newTitle = data[i][1]; //
Assuming the new title is in the second column var event = [Link](eventId);
if (event) { [Link](newTitle); } } } Export Google Sheets Data to a New Google Doc
function exportDataToDoc() { var sheet =
[Link]().getActiveSheet(); var values =
[Link]().getValues(); var doc = [Link]('Exported Data
Document'); var body = [Link](); [Link](function(row) { var line = [Link](' \t
'); // Tab-separated values [Link](line); }); } Automatically Backup Google
Sheets to Another Spreadsheet function backupSheet() { var sourceSheet =
[Link]().getActiveSheet(); var sourceData =
[Link]().getValues(); var backupSpreadsheet =
[Link]('your-backup-spreadsheet-id'); // Replace with your backup
spreadsheet ID var backupSheet = [Link]('Backup') ||
[Link]('Backup'); [Link](); // Clear existing data
[Link](1, 1, [Link],
sourceData[0].length).setValues(sourceData); } Setting Validation Rules in Google Sheets
function setValidationRules() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("B1:B10"); // Specify the range for validation // Create the data validation
rule var rule = [Link]() .requireValueInList(['Yes', 'No'],
true) .setAllowInvalid(false) .setHelpText('Select Yes or No') .build();
[Link](rule); } Creating a Google Calendar Event with Guests function
createCalendarEventWithGuests() { var calendar = [Link](); var
startTime = new Date(); var endTime = new Date([Link]() + 3600000); // Adds 1
hour var options = { guests: 'guest1@[Link],guest2@[Link]', sendInvites: true
}; [Link]('Meeting with Guests', startTime, endTime, options); } Appending a
Row to a Google Sheet from Form Submission function appendRowFromForm() { var
formResponse = ['John Doe', 'johndoe@[Link]', 'Feedback']; // Simulate form
response var sheet = [Link]().getActiveSheet();
[Link](formResponse); } Automatically Formatting New Rows in Google Sheets
function formatNewRows() { var sheet =
[Link]().getActiveSheet(); var lastRow =
[Link](); var range = [Link](lastRow, 1, 1, 3); // Adjust column length
as needed // Set the background color and text alignment for the new row
[Link]('#ffffcc').setHorizontalAlignment('center'); } Fetching and Logging
Weather Data function fetchWeatherData() { var response =
[Link]('[Link]
your_api_key'); // Replace 'your_api_key' with your actual API key var weatherData =
[Link]([Link]()); [Link]([Link]); // Log the
temperature } Bulk Removing Rows Based on Condition in Google Sheets function
bulkRemoveRows() { var sheet = [Link]().getActiveSheet();
var data = [Link]().getValues(); for (var i = [Link]- 1; i >= 0; i--) { if (data[i]
[0] === 'Remove') { // Check first column for 'Remove' [Link](i + 1); } } } Sending
Customized Email Based on Google Sheets Data function sendCustomEmails() { var sheet
= [Link]().getActiveSheet(); var range =
[Link](); var data = [Link](); for (var i = 1; i < [Link]; i++) { //
Skip header row var emailAddress = data[i][1]; // Assuming email addresses are in the
second column var message = 'Dear ' + data[i][0] + ', your custom message here.'; //
Assuming names are in the first column var subject = 'Your Custom Subject';
[Link](emailAddress, subject, message); } } Sync Google Sheets Data with
Google Calendar function syncSheetWithCalendar() { var sheet =
[Link]().getActiveSheet(); var eventsRange =
[Link]("A2:C10"); // Adjust range to your event details var events =
[Link](); var calendar = [Link]();
[Link](function(event) { var title = event[0]; var startTime = new Date(event[1]); var
endTime = new Date(event[2]); [Link](title, startTime, endTime); }); }
Generating a Report from Google Sheets and Emailing as a PDF function
generateAndEmailReport() { var sheet = [Link](); var
sheetId = [Link](); var sheetName = [Link](); var pdfUrl =
"[Link] + sheetId + "/export?
exportFormat=pdf&format=pdf"; var options = { headers: { 'Authorization': 'Bearer ' +
[Link]() } }; var response = [Link](pdfUrl, options); var blob
= [Link]().setName(sheetName + '.pdf');
[Link]("recipient@[Link]", "Monthly Report", "Please find the attached
report.", { attachments: [blob], }); } Removing Duplicate Entries in Google Sheets function
removeDuplicates() { var sheet = [Link]().getActiveSheet();
var data = [Link]().getValues(); var unique = {}; var uniqueRows = []; for (var i
= 0; i < [Link]; i++) { var row = data[i]; var key = [Link]("|"); // Create a unique key
from the row values if (!unique[key]) { unique[key] = true; [Link](row); } }
[Link](); // Clear the old data [Link](1, 1, [Link],
uniqueRows[0].length).setValues(uniqueRows); // Set the unique data } Splitting a String into
Multiple Cells in Google Sheets function splitStringIntoCells() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("A1"); // Assuming the string to be split is in A1 var stringValue =
[Link](); var splitValues = [Link](","); // Split by comma, change delimiter
as needed // Set the split values starting from B1 for (var i = 0; i < [Link]; i++)
{ [Link](1, i + 2).setValue(splitValues[i]); } } Merging Multiple Google Sheets into
One Sheet function mergeSheets() { var destinationSpreadsheet =
[Link](); var destinationSheet =
[Link]('Merged') ||
[Link]('Merged'); var spreadsheets = ['spreadsheetId1',
'spreadsheetId2']; // Add spreadsheet IDs for (var i = 0; i < [Link]; i++) { var
sheet = [Link](spreadsheets[i]).getActiveSheet(); var data =
[Link]().getValues();
[Link]([Link]() + 1, 1, [Link],
data[0].length).setValues(data); } } Highlighting Cells Based on Expiry Date function
highlightExpiryDates() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Select the range where expiry dates are stored var values =
[Link](); for (var i = 0; i < [Link]; i++) { var expiryDate = new Date(values[i]
[1]); // Assuming expiry dates are in the second column var today = new Date(); if
(expiryDate < today) { [Link](i + 1, 2).setBackground('red'); // Highlight expired
items } } } Automatically Add a Timestamp to a Row on Edit function onEdit(e) { var range =
[Link]; var sheet = [Link](); if ([Link]() === 'Sheet1' &&
[Link]() == 1 && [Link]) { // Check if edit is in column A of Sheet1 var
timestampCell = [Link]([Link](), 2); // Set timestamp in column B
[Link](new Date()); } } Convert Google Sheet Rows to JSON Objects
function convertRowsToJson() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); var headers = [Link](); //
Remove the first row with headers var jsonObjects = []; for (var i = 0; i < [Link]; i++)
{ var jsonObject = {}; for (var j = 0; j < [Link]; j++) { jsonObject[headers[j]] = values[i]
[j]; } [Link](jsonObject); } [Link]([Link](jsonObjects)); } Creating a
Function to Clear Specific Cells in Google Sheets function clearSpecificCells() { var sheet =
[Link]().getActiveSheet(); var cellsToClear = ['B2', 'C4',
'D6']; // Specify the cells to clear [Link](function(cellAddress)
{ [Link](cellAddress).clearContent(); }); } Function to Count Non-Empty Cells in a
Specific Column function countNonEmptyCells() { var sheet =
[Link]().getActiveSheet(); var column =
[Link]('A:A'); // Specify the column to count var values = [Link](); var
count = 0; [Link](function(row) { if (row[0]) count++; }); [Link]('Non-empty cells:
' + count); } Sending a Daily Digest Email from a Google Sheet function sendDailyDigest()
{ var sheet = [Link]().getActiveSheet(); var dataRange =
[Link](); var data = [Link](); var message = '';
[Link](function(row, index) { if (index > 0) { // Skip header row message += [Link](',
') + '\n'; // Format each row's values separated by commas } });
[Link]('recipient@[Link]', 'Daily Digest', message); } Auto-Resizing
Row Height in Google Sheets Based on Content function autoResizeRowHeight() { var sheet
= [Link]().getActiveSheet(); var range =
[Link](); var numRows = [Link](); for (var i = 1; i <= numRows;
i++) { [Link](i); } } Function to Replace Text in a Google Doc function
replaceTextInDoc() { var doc = [Link](); var body =
[Link](); [Link]('oldText', 'newText'); // Replace 'oldText' with 'newText' }
Batch Update Cell Background Color in Google Sheets function
batchUpdateCellBackground() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("A1:C10"); // Specify your range var backgrounds = []; for (var i = 0; i < 10;
i++) { // Assume 10 rows for example [Link](["#FF0000", "#00FF00",
"#0000FF"]); // Red, Green, Blue } [Link](backgrounds); } Create a List of
Hyperlinks in Google Sheets function createListOfHyperlinks() { var sheet =
[Link]().getActiveSheet(); var urls = [ ['Google',
'[Link] ['Bing', '[Link] ['DuckDuckGo',
'[Link] ]; // Array of [text, hyperlink] pairs var range =
[Link](1, 1, [Link], 2); // Adjust range according to the size of urls var formulas
= [Link](function(url) { return ['=HYPERLINK("' + url[1] + '", "' + url[0] + '")']; });
[Link](formulas); } Summarize Data from Multiple Sheets into a Master Sheet
function summarizeData() { var spreadsheet = [Link](); var
summarySheet = [Link]("Summary") ||
[Link]("Summary"); var sheets = [Link](); var
summaryData = []; [Link](function(sheet) { if ([Link]() !== "Summary")
{ var data = [Link]("A1:B10").getValues(); // Adjust your range summaryData =
[Link](data); } }); [Link](1, 1, [Link],
2).setValues(summaryData); } Convert Column Index to Letter in Google Sheets function
columnToLetter(column) { var temp, letter = ''; while (column > 0) { temp = (column- 1) % 26;
letter = [Link](temp + 65) + letter; column = (column- temp- 1) / 26; }
[Link](letter); } Automate Email Sending Based on Cell Value Changes function
onEditTrigger(e) { var range = [Link]; var sheet = [Link](); if ([Link]()
=== "Emails" && [Link]() == 2 && [Link]() === 'yes') { // Check if
edit is in the right column and sheet var emailAddress = [Link]([Link](),
1).getValue(); // Assuming email addresses are in the first column
[Link](emailAddress, 'Notification', 'Your custom message here.'); } } Extract
Email Addresses from Text function extractEmails() { var text = 'Your long text with
emails@[Link] somewhere in between'; var regex = /[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]
+\.[a-zA-Z]{2,4}/g; var emails = [Link](regex); [Link](emails); } Generate a Random
Password Generator in Google Sheets function generateRandomPassword() { var length =
12; // Define the length of the password var charset =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var
password = ''; for (var i = 0; i < length; i++) { var randomIndex = [Link]([Link]() *
[Link]); password += [Link](randomIndex); } [Link](password); } Delete
Rows Based on a Condition in Google Sheets function deleteRowsBasedOnCondition() { var
sheet = [Link]().getActiveSheet(); var lastRow =
[Link](); for (var i = lastRow; i >= 1; i--) { var cellValue = [Link](i,
1).getValue(); // Check values in the first column if (cellValue === 'Delete') { // Change
'Delete' to your condition [Link](i); } } } Create a Table of Contents for a Google
Doc function createTableOfContents() { var doc = [Link](); var
body = [Link](); var headings = [Link]().filter(function(paragraph)
{ return [Link]() !== [Link]; }); var toc
= [Link](); [Link](function(heading, index)
{ [Link]([[Link](), 'Page ' + (index + 1)]); }); } Updating Google
Calendar Event Descriptions in Bulk function updateCalendarEventDescriptions() { var
calendar = [Link](); var events = [Link](new
Date("2023-01-01"), new Date("2023-12-31")); // Specify your date range for (var i = 0; i <
[Link]; i++) { var event = events[i]; [Link]('Updated Description: ' +
[Link]()); } } Highlighting Weekends in Google Sheets function
highlightWeekends() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var numColumns = [Link](); var numRows =
[Link](); var dates = [Link](); for (var i = 0; i < numRows; i++) { for
(var j = 0; j < numColumns; j++) { var cellDate = dates[i][j]; if (cellDate instanceof Date) { var
dayOfWeek = [Link](); if (dayOfWeek == 0 || dayOfWeek == 6) { // 0 = Sunday, 6 =
Saturday [Link](i + 1, j + 1).setBackground('#FFF2CC'); } } } } } Inserting 'Last
Updated' Timestamp in Google Sheets Footer function insertLastUpdatedTimestamp() { var
sheet = [Link]().getActiveSheet(); var footer = "Last
Updated: " + new Date(); [Link]('A1').setValue(footer); // Change 'A1' to the cell
where you want the timestamp } Copy Google Sheet Data to Another Spreadsheet function
copyDataToAnotherSpreadsheet() { var sourceSheet =
[Link]().getActiveSheet(); var targetSpreadsheetId = 'your-
target-spreadsheet-id'; var targetSheetName = 'Sheet1'; var sourceRange =
[Link](); var sourceValues = [Link](); var
targetSpreadsheet = [Link](targetSpreadsheetId); var targetSheet =
[Link](targetSheetName); [Link](1, 1,
[Link], sourceValues[0].length).setValues(sourceValues); } Clear Contents
from Multiple Ranges in Google Sheets function clearMultipleRanges() { var sheet =
[Link]().getActiveSheet(); var rangesToClear = ['B2:D4',
'G5:H10', 'A12:A15']; // Define the ranges to clear [Link](function(range)
{ [Link](range).clearContent(); }); } Create Multiple Google Calendar Events from
Google Sheets Data function createMultipleCalendarEvents() { var sheet =
[Link]().getActiveSheet(); var dataRange =
[Link](); var eventDetails = [Link](); var calendar =
[Link](); for (var i = 1; i < [Link]; i++) { // Assuming
the first row is headers var [title, startDate, endDate] = eventDetails[i];
[Link](title, new Date(startDate), new Date(endDate)); } } Validate Email
Format in Google Sheets Using Regex function validateEmailFormat() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("A1:A10"); // Adjust the range accordingly var values = [Link]();
var regexPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Simple email validation pattern for (var i
= 0; i < [Link]; i++) { if (![Link](values[i][0])) { [Link](i + 1,
2).setValue("Invalid"); // Mark as invalid in the next column } else { [Link](i + 1,
2).setValue("Valid"); } } } Automatically Resize Images in Google Docs function
resizeImagesInDoc() { var doc = [Link](); var body =
[Link](); var images = [Link](); [Link](function(image) { var width
= [Link](); var height = [Link](); var newWidth = 200; // Set the desired
width var scaleFactor = newWidth / width; [Link](newWidth);
[Link](height * scaleFactor); }); } Convert Google Sheets Range to HTML Table
function convertRangeToHtmlTable() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); var htmlTable = ""; // Add headers
values[0].forEach(function(header) { htmlTable += ""; }); htmlTable += ""; // Add row data for
(var i = 1; i < [Link]; i++) { htmlTable += ""; values[i].forEach(function(cell) { htmlTable
+= ""; }); htmlTable += ""; } htmlTable += "
" + header + "

" + cell + "


"; [Link](htmlTable); } Automatically Sort Data in Google Sheets When a Cell Changes
function onEdit(e) { var range = [Link]; var sheet = [Link](); if ([Link]()
=== 'SortSheet' && [Link]() == 1) { // Change 'SortSheet' to your sheet name var
dataRange = [Link]("A2:B10"); // Change to the range you want to sort
[Link]({column: 1, ascending: true}); // Sort by the first column in ascending
order } } Fetch Latest Cryptocurrency Prices and Update Google Sheets function
updateCryptoPrices() { var apiURL = '[Link]
ids=bitcoin,ethereum&vs_currencies=usd '; var response = [Link](apiURL); var
json = [Link]([Link]()); var sheet =
[Link]().getActiveSheet();
[Link]('A1').setValue('Bitcoin'); [Link]('A2').setValue('Ethereum');
[Link]('B1').setValue([Link]);
[Link]('B2').setValue([Link]); } Compare Two Columns and Highlight
Mismatches in Google Sheets function highlightMismatches() { var sheet =
[Link]().getActiveSheet(); var range1 =
[Link]("A1:A10"); // First column range var range2 = [Link]("B1:B10"); //
Second column range var values1 = [Link](); var values2 = [Link]();
for (var i = 0; i < [Link]; i++) { if (values1[i][0] !== values2[i][0]) { [Link](i + 1,
1).setBackground('yellow'); [Link](i + 1, 1).setBackground('yellow'); } else
{ [Link](i + 1, 1).setBackground(null); [Link](i + 1, 1).setBackground(null); }
} } Automatically Hide Rows with Zero Values in Google Sheets function hideZeroRows()
{ var sheet = [Link]().getActiveSheet(); var dataRange =
[Link](); var values = [Link](); for (var i = [Link]- 1; i >=
0; i--) { if (values[i].some(function(value) { return value === 0; })) { [Link](i + 1); }
else { [Link](i + 1); } } } Send a Scheduled Email Reminder from Google Sheets
Data function sendScheduledReminder() { var sheet =
[Link]().getActiveSheet(); var dataRange =
[Link]("A2:B10"); // Assuming A has dates and B has email addresses var today =
new Date(); var data = [Link](); [Link](function(row) { var date = new
Date(row[0]); var email = row[1]; if ([Link]() === [Link]())
{ [Link](email, 'Reminder', 'This is your scheduled reminder.'); } }); } Export
Specific Google Sheets Data to a New Sheet function exportDataToNewSheet() { var
sourceSheet = [Link]().getActiveSheet(); var
targetSpreadsheet = [Link]('New Spreadsheet for Export'); var targetSheet
= [Link](); var dataRange =
[Link]("A1:C10"); // Adjust range as needed var data =
[Link](); [Link](1, 1, [Link],
data[0].length).setValues(data); } Validate Data Entry as Email Format in Google Sheets
function validateEmailEntry() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("B1:B10"); // Adjust range for your needs var rule =
[Link]().requireTextIsEmail().build();
[Link](rule); } Log Changes in Google Sheets to a Separate Sheet function
logChanges(e) { var range = [Link]; var sheet = [Link](); var logSheet =
[Link]().getSheetByName('Change Log') || [Link]().insertSheet('Change
Log'); var oldValue = [Link] || 'None'; var newValue = [Link] || 'None'; var timestamp =
new Date(); var user = [Link]().getEmail();
[Link]([timestamp, user, range.getA1Notation(), oldValue, newValue]); }
Generate QR Codes in Google Sheets function generateQRCodes() { var sheet =
[Link]().getActiveSheet(); var dataRange =
[Link]("A2:A"); // Adjust the range according to where your data is var values =
[Link](); for (var i = 0; i < [Link]; i++) { var data = values[i][0]; if (data)
{ var url = "[Link] + encodeURIComponent(data) +
"&chs=100x100"; [Link](i + 2, 2).setValue(url); // Assuming you want the QR code
links in the second column } } } Summarize Google Forms Responses in Google Sheets
function summarizeFormResponses() { var sheet =
[Link]().getSheetByName('Form Responses 1'); // Change
to your form response sheet name var dataRange = [Link](); var responses =
[Link](); var summary = {}; // Assuming first row is headers, skip it for (var i =
1; i < [Link]; i++) { var response = responses[i]; for (var j = 0; j < [Link];
j++) { var question = responses[0][j]; var answer = response[j]; summary[question] =
summary[question] || {}; summary[question][answer] = (summary[question][answer] || 0) +
1; } } // Log summary for review or further processing [Link](summary); } Auto-Generate
Document Based on Google Sheets Data function generateDocumentFromSheetData() { var
sheet = [Link]().getActiveSheet(); var data =
[Link]("A1:B1").getValues(); // Adjust range as needed var doc =
[Link]('Generated Document from Sheet'); var body = [Link]();
[Link](function(row) { [Link](row[0] + ': ' + row[1]); // Assuming key-
value pairs in each row }); [Link]('Document created with ID: ' + [Link]()); } Create
and Format a New Google Sheet from Script function createAndFormatSheet() { var
newSheetName = 'Monthly Report'; // Change as required var spreadsheet =
[Link](newSheetName); var sheet = [Link](); // Set
up header row var headers = ['Date', 'Category', 'Amount']; var headerRange =
[Link]("A1:C1"); [Link]([headers]);
[Link]('bold'); [Link](1, 3, 150); // Set widths for the
first three columns [Link]('Spreadsheet created with name: ' + newSheetName); }
Change Google Sheets Tab Color Based on Cell Value function
updateTabColorBasedOnValue() { var sheet =
[Link]().getActiveSheet(); var status =
[Link]('A1').getValue(); // Assuming status is in A1 if (status === 'Complete')
{ [Link]('green'); } else if (status === 'In Progress') { [Link]('yellow');
} else { [Link](null); // Remove color if status is neither } } Automatically Number
Rows in Google Sheets function autoNumberRows() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Get range of data var values = [Link](); for (var i = 0; i <
[Link]; i++) { values[i][0] = i + 1; // Assuming the row number should go in the first
column } [Link](values); } Remove Empty Rows from the End of Google Sheets
function removeEmptyRows() { var sheet =
[Link]().getActiveSheet(); var lastRow =
[Link](); var lastColumn = [Link](); var range =
[Link](lastRow, 1, 1, lastColumn); var values = [Link](); while
(values[0].every(function(value) { return value === ""; })) { [Link](lastRow);
lastRow--; range = [Link](lastRow, 1, 1, lastColumn); values = [Link](); }
} Convert Selected Range to Uppercase in Google Sheets function
convertRangeToUppercase() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Get the current selected range var values = [Link]();
var newValues = [Link](function(row) { return [Link](function(cell) { return typeof cell
=== 'string' ? [Link]() : cell; }); }); [Link](newValues); } Sync Google
Sheets Data with a Secondary Sheet function syncSheets() { var primarySheet =
[Link]().getSheetByName("Primary"); var secondarySheet
= [Link]().getSheetByName("Secondary"); var data =
[Link]().getValues(); [Link](); // Clear existing data
[Link](1, 1, [Link], data[0].length).setValues(data); // Copy data to
secondary sheet } Generate a List of All Hyperlinks in Google Sheets function
listAllHyperlinks() { var sheet = [Link]().getActiveSheet();
var range = [Link](); var formulas = [Link](); var links = []; for
(var i = 0; i < [Link]; i++) { for (var j = 0; j < formulas[i].length; j++) { var cellFormula
= formulas[i][j]; if ([Link]('=HYPERLINK')) { [Link](cellFormula); } } }
[Link](links); } Create Google Calendar Events from Selected Range in Google Sheets
function createEventsFromRange() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Get the current selected range var values = [Link]();
var calendar = [Link](); [Link](function(row) { var title =
row[0]; var startTime = new Date(row[1]); var endTime = new Date(row[2]);
[Link](title, startTime, endTime); }); } Highlight Duplicate Entries in Google
Sheets function highlightDuplicates() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); var duplicates = [];
[Link](function(row, rowIndex) { [Link](function(cell, columnIndex) { if
([Link](rowIndex + 1).some(r => r[columnIndex] === cell)) { [Link]([rowIndex
+ 1, columnIndex + 1]); } }); }); [Link](function(cellPosition)
{ [Link](cellPosition[0], cellPosition[1]).setBackground('red'); }); } Automatically
Format New Google Sheets Entries as Currency function formatAsCurrency() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("B1:B"); // Assuming column B should be in currency format
[Link]("$#,##0.00"); } Compare Two Google Sheets for Differences
function compareSheets() { var ss = [Link](); var sheet1 =
[Link]("Sheet1"); var sheet2 = [Link]("Sheet2"); var range1 =
[Link](); var range2 = [Link](); var values1 =
[Link](); var values2 = [Link](); var maxRows =
[Link]([Link], [Link]); var maxCols = [Link](values1[0].length,
values2[0].length); for (var i = 0; i < maxRows; i++) { for (var j = 0; j < maxCols; j++) { var
value1 = (values1[i] && values1[i][j]) || ""; var value2 = (values2[i] && values2[i][j]) || ""; if
(value1 !== value2) { // Highlight differences in Sheet1 if ([Link]() >= i + 1 &&
[Link]() >= j + 1) { [Link](i + 1, j + 1).setBackground('yellow'); } //
Highlight differences in Sheet2 if ([Link]() >= i + 1 && [Link]()
>= j + 1) { [Link](i + 1, j + 1).setBackground('yellow'); } } } } } Append Google
Form Responses to a Google Doc function appendFormResponsesToDoc() { var
formResponses = [Link]().getResponses(); var doc =
[Link]('your-document-id'); // Replace with your Google Doc ID var body =
[Link](); [Link](function(response) { var itemResponses =
[Link](); [Link](function(itemResponse)
{ [Link]([Link]().getTitle() + ": " +
[Link]()); }); [Link](); // Adds a visual break
between each form response }); } Clear Formatting in a Selected Range in Google Sheets
function clearFormatting() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Get the current selected range [Link](); } Insert
Current Date and Time in a Cell on Edit function onEdit(e) { var sheet =
[Link](); var editRange = [Link](); var dateCell =
[Link]([Link](), [Link]() + 1); // Assuming date is
always next to the edited cell [Link](new Date()); } Automatically Convert
Incoming Emails to Google Docs function convertEmailsToDocs() { var threads =
[Link](0, 5); // Fetch up to 5 latest email threads
[Link](function(thread) { var messages = [Link]();
[Link](function(message) { var doc = [Link]('Email from: ' +
[Link]()); [Link]().setText([Link]()); }); }); } Create a Pie
Chart in Google Sheets from Data function createPieChart() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("A1:B6"); // Adjust range for your data var chart =
[Link]() .setChartType([Link]) .addRange(range) .setPosition(5, 5,
0, 0) .build(); [Link](chart); } Send a Custom Slack Message from a Google Sheet
function sendSlackMessage() { var webhookUrl = 'your-slack-webhook-url'; // Replace with
your Slack webhook URL var message = { "text": "Here is a message from Google
Sheets!" }; var options = { "method": "post", "contentType": "application/json", "payload":
[Link](message) }; [Link](webhookUrl, options); } Update a Cell Based
on Changes in Another Cell function onEdit(e) { var sourceSheet =
[Link](); if ([Link]() === 'Sheet1') { // Specify the sheet to
watch var editedCell = [Link](); if (editedCell.getA1Notation() ===
'A1') { // Check if the edited cell is A1 var newValue = [Link](); var targetCell =
[Link]('B1'); // Specify the target cell [Link](newValue * 2); //
Example action, multiply A1 value by 2 } } } Batch Create Google Calendar Events from
Spreadsheet Data function batchCreateEvents() { var sheet =
[Link]().getActiveSheet(); var startRow = 2; // Assuming
the first row has headers var numRows = [Link]()- 1; var dataRange =
[Link](startRow, 1, numRows, 4); // Adjust 4 to the number of columns var data =
[Link](); var calendar = [Link](); for (var i = 0; i <
[Link]; i++) { var row = data[i]; var title = row[0]; // First column var startTime = new
Date(row[1]); // Second column var endTime = new Date(row[2]); // Third column var options
= {description: row[3]}; // Fourth column for description [Link](title, startTime,
endTime, options); } } Color Code Cells Based on Expiry Date in Google Sheets function
colorCodeExpiryDates() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]("A2:B10"); // Assuming A column has dates and B column is to be colored
var values = [Link](); var today = new Date(); for (var i = 0; i < [Link]; i++) {
var expiryDate = new Date(values[i][0]); var daysLeft = (expiryDate- today) / (1000 * 3600 *
24); if (daysLeft < 0) { [Link]('B' + (i + 2)).setBackground('red'); // Past expiry date }
else if (daysLeft < 30) { [Link]('B' + (i + 2)).setBackground('yellow'); // Expiring
soon } else { [Link]('B' + (i + 2)).setBackground('green'); // Valid } } } Auto-Delete
Rows Based on Cell Content in Google Sheets function autoDeleteRows() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); for (var i = [Link]- 1; i >= 0;
i--) { if (values[i][0] === "Delete") { // Assuming the trigger word is in the first column
[Link](i + 1); } } } Convert All Formulas to Values in Google Sheets function
convertFormulasToValues() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); // Select all data in the sheet var values = [Link](); // Get
all values, formulas are evaluated [Link](values); // Set evaluated values back,
converting all formulas to static values } Auto-Generate and Email a Google Sheets Report
as PDF function emailSheetAsPDF() { var ss = [Link]();
var sheet = [Link](); var sheetId = [Link](); var url =
'[Link] + [Link]() + '/export?format=pdf&gid=' + sheetId;
var response = [Link](url, { headers: { 'Authorization': 'Bearer ' +
[Link]() } }); var blob = [Link]().setName([Link]() +
'.pdf'); [Link]('recipient@[Link]', 'Your Google Sheets Report', 'Please
find the attached report.', { attachments: [blob] }); } Set Data Validation for a Range Based
on Another Column's Values function setDataValidationBasedOnColumn() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]('B1:B10'); // Range to apply validation to var criteriaRange =
[Link]('A1:A10'); // Range to take validation criteria from var rule =
[Link]().requireValueInRange(criteriaRange, true).build();
[Link](rule); } Highlight Cells in Google Sheets That Contain Formulas
function highlightFormulas() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var formulas = [Link](); for (var i = 0; i <
[Link]; i++) { for (var j = 0; j < formulas[i].length; j++) { if (formulas[i][j]) { // If cell
contains a formula [Link](i + 1, j + 1).setBackground('#FFFF00'); // Highlight with
yellow } } } } Automatically Add Google Calendar Events to a Google Sheet function
importCalendarEvents() { var sheet =
[Link]().getActiveSheet(); var calendar =
[Link](); var events = [Link](new Date(), new
Date(new Date().getTime() + 7 * 24 * 3600 * 1000)); // Fetch events for the next 7 days
[Link](function(event) { [Link]([[Link](), [Link](),
[Link]()]); }); } Create a Google Sheets Log for Failed Email Attempts function
logFailedEmails() { var sheet =
[Link]().getSheetByName('Email Log'); var data =
[['[Link]@[Link]', 'Failed'], ['[Link]@[Link]', 'Success']]; // Sample data
[Link](function(row) { if (row[1] === 'Failed') { [Link](row); // Log only
failed email attempts } }); } Batch Clear Multiple Named Ranges in Google Sheets function
clearNamedRanges() { var ss = [Link](); var
namedRanges = [Link](); [Link](function(namedRange)
{ [Link]().clearContent(); // Clear content of each named range }); } Merge
Multiple Google Docs into One Document function mergeGoogleDocs() { var docIds = ['doc-
id-1', 'doc-id-2', 'doc-id-3']; // Array of Google Docs IDs to merge var finalDoc =
[Link]('Merged Document'); [Link](function(id) { var body =
[Link](id).getBody(); var elements = [Link]();
[Link](function(element) { [Link]().appendParagraph([Link]());
}); [Link]().appendPageBreak(); }); } Auto-Format Negative Numbers in Red in
Google Sheets function formatNegativeNumbers() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); [Link](function(row,
rowIndex) { [Link](function(cell, columnIndex) { if (typeof cell === 'number' && cell < 0)
{ [Link](rowIndex + 1, columnIndex + 1).setFontColor('red'); } }); }); } Extract and
Summarize Checked Items from Google Forms Checkbox Questions function
summarizeCheckedItems() { var form = [Link](); var formResponses =
[Link](); var itemResponses = [Link](response =>
[Link]()); var summary = {}; [Link](response =>
{ [Link](itemResponse => { var answers = [Link](); if
([Link](answers)) { // Check if response is from a checkbox question
[Link](answer => { summary[answer] = (summary[answer] || 0) + 1; }); } }); });
[Link](summary); // Log the summary of checked items } Automate Data Backups in
Google Sheets function backupSheetData() { const sourceSheet =
[Link]().getActiveSheet(); const backupSpreadsheet =
[Link]('your-backup-spreadsheet-id'); // Replace with your backup
spreadsheet ID const backupSheet = [Link]('Backup') ||
[Link]('Backup'); const data =
[Link]().getValues(); [Link](); // Clear the existing data
[Link](1, 1, [Link], data[0].length).setValues(data); // Copy new data }
Track Cell Edits and Timestamps in a Separate Google Sheets Tab function onEdit(e)
{ const editSheet = [Link](); const logSheet =
[Link]('Edit Log') || [Link]('Edit Log'); const timestamp =
new Date(); const editRange = [Link].getA1Notation(); const oldValue = [Link] ||
'Empty'; const newValue = [Link] || 'Empty'; [Link]([timestamp,
[Link](), editRange, oldValue, newValue]); } Summarize Selected Google
Sheets Data in an Email function summarizeAndEmailData() { const sheet =
[Link]().getActiveSheet(); const range =
[Link](); const values = [Link](); let summary = 'Your Data
Summary:\n\n'; // Customize this loop for your specific summarization needs
[Link]((row, index) => { summary += `Row ${index + 1}: ${[Link](', ')}\n`; });
[Link]('recipient@[Link]', 'Google Sheets Data Summary',
summary); } Find and Replace Text in Multiple Google Docs function
findAndReplaceInDocs() { const docsIds = ['doc-id-1', 'doc-id-2']; // Array of document IDs
const findText = 'oldText'; const replaceText = 'newText'; [Link]((id) => { const
body = [Link](id).getBody(); [Link](findText, replaceText); }); }
Create a Dropdown List from Range in Google Sheets function
createDropdownFromRange() { const sheet =
[Link]().getActiveSheet(); const range =
[Link]('A1:A10'); // Range for the dropdown list const validationRule =
[Link]().requireValueInRange(range, true).build();
[Link]('B1').setDataValidation(validationRule); // Cell to have dropdown }
Automatically Move Google Sheets Rows to Another Tab Based on Cell Value function
moveRowsBasedOnValue() { const sourceSheet =
[Link]().getSheetByName('Source'); const targetSheet =
[Link]().getSheetByName('Target'); const rows =
[Link]().getValues(); [Link]((row, index) => { if (row[0] ===
'Move') { // Check if the first cell in the row has 'Move' [Link](row); //
Append row to target sheet [Link](index + 1); // Remove row from source
sheet } }); } Generate and Insert a Google Sheets Chart into a Google Slide function
insertChartIntoSlides() { const sheet =
[Link]().getSheetByName('Data'); const slides =
[Link]('your-slides-id'); // Replace with your Google Slides ID const slide =
[Link]()[0]; // Get the first slide const dataRange = [Link]('A1:B5'); //
Adjust range to your data const chart =
[Link]() .setChartType([Link]) .addRange(dataRange) .setPositio
n(5, 5, 0, 0) .build(); [Link](chart); const embeddedChart = [Link]();
[Link](embeddedChart); } Extract All Email Addresses from a Gmail Thread
function extractEmailsFromThread() { const thread = [Link](0, 1)[0]; //
Get the first thread in your inbox const messages = [Link](); const
emailAddresses = []; [Link]((message) => { const from = [Link]();
const to = [Link](); const cc = [Link](); [Link](from, to,
cc); }); [Link]([Link](', ')); // Log all email addresses found } Auto-Create a
Monthly Calendar in Google Sheets function createMonthlyCalendar() { const sheet =
[Link]().insertSheet('Monthly Calendar'); const days =
['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; const today = new Date(); const firstDay = new
Date([Link](), [Link](), 1); const lastDay = new
Date([Link](), [Link]() + 1, 0); const dates = []; // Set up days header
[Link]('A1:G1').setValues([days]).setFontWeight('bold'); // Generate dates for the
month for (let d = firstDay; d <= lastDay; [Link]([Link]() + 1)) { [Link](new
Date(d)); } // Populate the calendar let row = 2; for (let i = 0; i < [Link]; i++) { const
column = dates[i].getDay() + 1; [Link](row, column).setValue(dates[i].getDate()); if
(column === 7) row++; } } Monitor and Log Google Sheets Cell Changes Over Time function
logCellChanges(e) { const changeLogSheet =
[Link]().getSheetByName('Change Log') ||
[Link]().insertSheet('Change Log'); const cell =
[Link].getA1Notation(); const oldValue = [Link] || 'None'; const newValue = [Link] ||
'None'; const timestamp = new Date(); // Log the change
[Link]([timestamp, cell, oldValue, newValue]); } Automatically Color-
code Google Calendar Events Based on Keywords function colorCodeCalendarEvents()
{ var calendar = [Link](); var events = [Link](new
Date(), new Date(new Date().getTime() + 30 * 24 * 3600 * 1000)); // Next 30 days
[Link](function(event) { var title = [Link]().toLowerCase(); if
([Link]('birthday')) { [Link]([Link].PALE_BLUE); } else if
([Link]('meeting')) { [Link]([Link]); } else if
([Link]('deadline')) { [Link]([Link]); } }); } Create a
Directory of Files and Folders in Google Drive function createDriveDirectoryListing() { var
folderId = 'your-folder-id'; // Replace with your folder ID var folder =
[Link](folderId); var contents = [Link](); var listing = [['Name',
'Type', 'URL', 'Last Updated']]; while ([Link]()) { var file = [Link]();
[Link]([[Link](), [Link](), [Link](), [Link]()]); } var
sheet = [Link]().getActiveSheet(); [Link](1, 1,
[Link], 4).setValues(listing); } Export Google Sheets Charts as Images function
exportChartsAsImages() { var sheet =
[Link]().getActiveSheet(); var charts = [Link]();
[Link](function(chart, index) { var blob = [Link]();
[Link]([Link]('Chart_' + (index + 1) + '.png')); }); } Sync Google Sheets
Data with Google Contacts function syncSheetWithContacts() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); // Assuming first row is headers
[Link](function(row, index) { if (index > 0) { // Skip header row var contact =
[Link](row[0], row[1], row[2]); // Assuming Name, Last Name, Email in
columns [Link]([Link].MOBILE_PHONE, row[3]); // Assuming
phone number in fourth column } }); } Auto-Sort Google Sheets When a New Row is Added
function onEdit(event) { var sheet = [Link](); var editedCell =
[Link](); if ([Link]() == 1 && [Link]() ==
'YourSheetName') { // Check if edit is in the first row and correct sheet var range =
[Link]('A2:Z' + [Link]()); [Link]({column: 1, ascending: true}); //
Sort by first column, A-Z } } Remove Duplicate Rows Based on a Specific Column in Google
Sheets function removeDuplicatesBasedOnColumn() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); var uniqueRecords = {}; var rowsToDelete = [];
[Link](function(row, index) { if ([Link](row[0])) { // Assuming
duplicates based on the first column [Link](index + 1); } else
{ uniqueRecords[row[0]] = true; } }); [Link](); // Delete from the bottom to
avoid messing up indices [Link](function(rowIndex)
{ [Link](rowIndex); }); } Insert Current Weather Information into Google Sheets
function insertCurrentWeather() { var apiKey = 'your-openweather-api-key'; // Replace with
your OpenWeather API key var city = 'London,uk'; // Replace with your city var url =
'[Link] + city + '&appid=' + apiKey +
'&units=metric'; var response = [Link](url); var json =
[Link]([Link]()); var sheet =
[Link]().getActiveSheet();
[Link]('A1').setValue('Current Temperature (°C)');
[Link]('A2').setValue([Link]); } Convert Google Sheet Rows to Individual
Text Files function convertRowsToTextFiles() { var sheet =
[Link]().getActiveSheet(); var rows =
[Link]().getValues(); [Link](function(row, index) { var text = [Link](',
'); // Combine all cell values in the row, separated by commas var fileName = 'Row_' + (index
+ 1) + '.txt'; [Link](fileName, text); }); } Monitor Google Sheets Cell Value and
Send Alert if Changed function monitorCellValue() { var sheet =
[Link]().getActiveSheet(); var cellToMonitor =
[Link]('A1').getValue(); // Change 'A1' to the cell you want to monitor var
triggerValue = 100; // Change 100 to the value that triggers the alert if (cellToMonitor >
triggerValue) { [Link]('your-email@[Link]', 'Alert: Cell Value Changed',
'The value of cell A1 exceeds ' + triggerValue); } } Create a Checklist in Google Sheets with
Checkboxes function createChecklist() { var sheet =
[Link]().getActiveSheet(); var tasks = ['Task 1', 'Task 2',
'Task 3']; // Replace with your tasks var range = [Link]('A1:A' + [Link]);
[Link]([Link](function(task) { return [task]; })); [Link](0,
1).insertCheckboxes(); } Auto-generate Google Calendar Events from Task List in Google
Sheets function generateCalendarEventsFromTasks() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); // Assuming tasks start from row 2 var calendar =
[Link](); [Link](function(row, index) { if (index > 0 &&
row[0] && !row[4]) { // Assuming tasks in column A and completion flag in column E var title =
row[0]; var startDate = new Date(row[1]); var endDate = new Date(row[2]); var description =
row[3]; var event = [Link](title, startDate, endDate, {description: description});
[Link](index + 1, 5).setValue('Created'); // Mark as 'Created' } }); } Highlight
Overdue Tasks in Google Sheets function highlightOverdueTasks() { var sheet =
[Link]().getActiveSheet(); var tasks =
[Link]('A2:B' + [Link]()).getValues(); // Assuming due dates are in
column B [Link](function(row, i) { var dueDate = row[1]; if (dueDate instanceof Date
&& dueDate < new Date()) { [Link](i + 2, 2).setBackground('red'); // Highlight
overdue tasks } }); } Convert Sheet Data to JSON and Log It function sheetDataToJson()
{ var sheet = [Link]().getActiveSheet(); var data =
[Link]().getValues(); var headers = [Link](); // Remove the first row with
headers var jsonData = []; [Link](function(row) { var obj = {};
[Link](function(header, i) { obj[header] = row[i]; }); [Link](obj); });
[Link]([Link](jsonData)); } Batch Resize Images in Google Drive function
batchResizeImages() { var folder = [Link]('your-folder-id'); // Replace with
your folder ID var images = [Link]([Link]); // Change MIME type
as needed while ([Link]()) { var image = [Link](); var blob =
[Link](); var resizedImage = [Link](blob).resize(100,
100).getBlob(); // Resize to 100x100 pixels
[Link](resizedImage).setName('Resized_' + [Link]()); } } Insert
Formatted Date and Time in a Cell function insertFormattedDateTime() { var sheet =
[Link]().getActiveSheet(); var cell =
[Link]('A1'); // Change to the target cell var now = new Date(); var formattedDate =
[Link](now, [Link](), 'yyyy-MM-dd HH:mm:ss');
[Link](formattedDate); } Validate Email Addresses in a Column function
validateEmailAddresses() { var sheet =
[Link]().getActiveSheet(); var emails =
[Link]('A2:A' + [Link]()).getValues(); // Assuming emails in column A
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; [Link](function(email, i) { if (!
[Link](email[0])) { [Link](i + 2, 1).setBackground('yellow'); // Highlight
invalid emails } }); } Automatically Close Google Form Submissions After a Certain Number
of Responses function closeFormAfterResponses() { var form = [Link]();
var maxResponses = 100; // Set the maximum number of responses var responses =
[Link]().length; if (responses >= maxResponses)
{ [Link](false).setCustomClosedFormMessage('We have reached the
maximum number of responses. Thank you!'); } } Create a Progress Tracker in Google
Sheets function createProgressTracker() { var sheet =
[Link]().getActiveSheet(); var tasks = ['Task 1', 'Task 2',
'Task 3', 'Task 4']; // Example tasks var totalTasks = [Link];
[Link]('A1').setValue('Task'); [Link]('B1').setValue('Status');
[Link](function(task, index) { [Link]('A' + (index + 2)).setValue(task);
[Link]('B' + (index + 2)).setValue('=IF(C' + (index + 2) + '="", "", IF(C' + (index + 2)
+ ' < 100, "In Progress", "Completed"))'); [Link]('C' + (index +
2)).setValue('').setDataValidation([Link]().requireNumber
Between(0, 100).build()).setBackground('#dddddd'); }); [Link](3, 100);
[Link]('C1').setValue('Progress (%)'); [Link]('A1:C' + (totalTasks +
1)).applyRowBanding([Link].LIGHT_GREY); } Generate Unique
ID for Each Google Sheets Row function generateUniqueIds() { var sheet =
[Link]().getActiveSheet(); var range =
[Link]('A2:A' + [Link]()); // Assuming IDs to be in column A var values
= [Link](); [Link](function(row, index) { if (!row[0]) { // If ID cell is empty
var uniqueId = [Link](); // Generate a unique ID [Link]('A' + (index +
2)).setValue(uniqueId); } }); } Extract Specific Data from Gmail Messages to Google Sheets
function extractDataFromGmail() { var sheet =
[Link]().getActiveSheet(); var threads =
[Link]('subject:"Your Subject Filter"'); // Adjust search query as needed var
messages = [Link](threads);
[Link](function(thread, i) { [Link](function(message) { var subject =
[Link](); var date = [Link](); var body =
[Link](); // Extract specific information from the email body using regex, if
necessary [Link]([subject, date, body]); // Adjust according to the data you want
to extract }); }); } Automatically Update Google Sheets with Stock Prices function
updateStockPrices() { var sheet =
[Link]().getActiveSheet(); var symbols = ['AAPL', 'GOOGL',
'MSFT']; // Example stock symbols var prices = []; [Link](function(symbol) { var url
= '[Link] + symbol + '/price'; var response =
[Link](url); var price = parseFloat([Link]());
[Link]([symbol, price]); }); [Link](1, 1, [Link], 2).setValues(prices); }
Automatically Archive Gmail Messages in Google Sheets function archiveGmailMessages() {
var sheet = [Link]().getActiveSheet(); var threads =
[Link]('label:inbox is:unread'); // Example search query var messages =
[Link](threads); [Link](function(thread)
{ [Link](function(message) { var subject = [Link](); var sender =
[Link](); var date = [Link](); [Link]([subject, sender,
date]); [Link](); }); }); } Automatically Generate Google Calendar Events from
Google Forms Responses function createEventsFromFormResponses() { var form =
[Link]('your-form-id'); // Replace with your Form ID var responses =
[Link](); var calendar = [Link]();
[Link](function(response) { var itemResponses =
[Link](); var title = itemResponses[0].getResponse(); // Assuming first
question is event title var startTime = new Date(itemResponses[1].getResponse()); //
Assuming second question is start time var endTime = new
Date(itemResponses[2].getResponse()); // Assuming third question is end time
[Link](title, startTime, endTime); }); } Automatically Send Email Notifications
for Google Forms Responses function sendEmailNotificationsForFormResponses() { var
form = [Link]('your-form-id'); // Replace with your Form ID var responses =
[Link](); [Link](function(response) { var respondentEmail =
[Link](); var itemResponses = [Link](); var
message = 'Thank you for submitting the form. Your response has been received.'; var
subject = 'Form Submission Confirmation'; [Link](respondentEmail, subject,
message); }); } Automatically Create Google Calendar Events from Google Sheets Data
function createCalendarEventsFromSheetData() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); var calendar = [Link]();
[Link](function(row) { var title = row[0]; // Assuming event title in first column var
startTime = new Date(row[1]); // Assuming start time in second column var endTime = new
Date(row[2]); // Assuming end time in third column [Link](title, startTime,
endTime); }); } Automatically Track Changes to Google Sheets with Revision History function
trackSheetChanges() { var sheet =
[Link]().getActiveSheet(); var revisions =
[Link](); [Link](function(revision) { [Link]('Revision ID: ' +
[Link]()); [Link]('User: ' + [Link]()); [Link]('Timestamp: '
+ [Link]()); [Link]('Changes: ' + [Link]()); }); }
Automatically Generate QR Codes from URLs in Google Sheets function
generateQRCodesFromURLs() { var sheet =
[Link]().getActiveSheet(); var urls =
[Link]('A:A').getValues(); // Assuming URLs are in column A
[Link](function(url, index) { var qrCode = '[Link]
data=' + encodeURIComponent(url); [Link](qrCode, index + 1, 2); // Insert QR
code in column B }); } Automatically Generate Google Docs from Google Sheets Data
function generateDocsFromSheetData() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); [Link](function(row) { var title = row[0]; //
Assuming document title in first column var body = row[1]; // Assuming document content in
second column [Link](title).getBody().setText(body); }); } Automatically
Translate Google Sheets Data function translateSheetData() { var sheet =
[Link]().getActiveSheet(); var range =
[Link](); var values = [Link](); var translatedValues = [];
[Link](function(row) { var translatedRow = []; [Link](function(cell) { var
translatedCell = [Link](cell, 'en', 'fr'); // Translate from English to French
[Link](translatedCell); }); [Link](translatedRow); });
[Link](translatedValues); } Automatically Generate Google Slides Presentations
from Google Sheets Data function generateSlidesFromSheetData() { var sheet =
[Link]().getActiveSheet(); var data =
[Link]().getValues(); var slides = [Link]('Presentation from Sheet
Data'); var presentation = [Link](); [Link](function(row) { var slide =
[Link](); var slideTitle = row[0]; // Assuming slide title in first column var
slideBody = row[1]; // Assuming slide content in second column
[Link](slideTitle, 100, 100).insertText(0, 0, slideBody); }); }

You might also like