Boost Productivity With These Excellent Google Spreadsheet Scripts

Embed Size (px)

Citation preview

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    1/7

    http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/ Created with PrintWhatYouLike.com

    Boost Productivity With These Excellent

    Scripts

    Did you know that the suite of products on Google Drive (https://drive.google.com), especial

    extended by custom scripts? These scripts can dramatically improve your productivity (http:

    drive-which-is-best-for-office-productivity/) while using Google Spreadsheet, and it’s relative

    own!

    If you use a spreadsheet application to crunch data, then custom scripts could be the mast

    Spreadsheet scripts and make use of your data in new ways.

    How To Use Scripts

    Let's go

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    2/7

    http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/ Created with PrintWhatYouLike.com

    Before you begin drooling over the following Google Spreadsheet scripts, it’s important to k

    1. To add a script, you’ll need to log into Google Drive, go to a spreadsheet, choose Tools

    2. Copy and paste the script code, and then click on Save.

    3. To run the script, just go to Tools — Script Manager  and choose the function you want.

    name in the first line of the script, i.e. function removeDuplicates() results in the script being

    For all of you scripting and programming nerds, the scripts are written in JavaScript (http:// works/). Google has various resources that describe the API (https://developers.google.com

     you need to catch up on your JavaScript, there are plenty of free JavaScript resources (http:

    resources-for-learning-javascript-by-doing/) you can use.

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    3/7

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    4/7

    http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/ Created with PrintWhatYouLike.com

    sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData);

    }

    With a bit of research, I am sure that this script can also be tweaked to count the number of

    entries first and then delete the duplicates.

    Send Email From Spreadsheet

    Did you know that you can also send emails from a spreadsheet? Absolutely! For this specifi

    message body, but the subject line is fixed. You can change it in the script code, or you can

    between the recipient and the message body for a subject. Then, just modify the number of i

    script code for this is:

    function sendEmails() {

    var sheet = SpreadsheetApp.getActiveSheet();

    var startRow = 2; // First row of data to process

    var numRows = 2; // Number of rows to process

     // Fetch the range of cells A2:B3

    var dataRange = sheet.getRange(startRow, 1, numRows, 2)

     // Fetch values for each row in the Range.

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    5/7

    http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/ Created with PrintWhatYouLike.com

    var data = dataRange.getValues();

    for (i in data) {

    var row = data[i];

    var emailAddress = row[0]; // First column

    var message = row[1]; // Second column

    var subject = "Sending emails from a Spreadsheet";MailApp.sendEmail(emailAddress, subject, message);

    }

    }

    Expanded Conditional Formatting

    One of the most useful features of spreadsheets is conditional formatting — a custom rule o

    (such as fill color) depending on the content of the cell. It works well, but it is also limited for

    formatting to an entire row, for example, then you’ll need to use a script.

     This here is an example script that should do the job. This script sets the row color dependi

    function setRowColors() {

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    6/7

    http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/ Created with PrintWhatYouLike.com

    var range = SpreadsheetApp.getActiveSheet().getDataRange();

    var statusColumnOffset = getStatusColumnOffset();

    for (var i = range.getRow(); i < range.getLastRow(); i++) {

    rowRange = range.offset(i, 0, 1);

    status = rowRange.offset(0, statusColumnOffset).getValue();

    if (status == 'Completed') {rowRange.setBackgroundColor("#99CC99");

    } else if (status == 'In Progress') {

    rowRange.setBackgroundColor("#FFDD88");

    } else if (status == 'Not Started') {

    rowRange.setBackgroundColor("#CC6666");

    }

    }

    }

     //Returns the offset value of the column titled "Status"

     //(eg, if the 7th column is labeled "Status", this function returns 6)

    function getStatusColumnOffset() {

    lastColumn = SpreadsheetApp.getActiveSheet().getLastColumn();

    var range = SpreadsheetApp.getActiveSheet().getRange(1,1,1,lastColumn);

    for (var i = 0; i < range.getLastColumn(); i++) {

    if (range.offset(0, i, 1, 1).getValue() == "Status") {

    return i;

    }

    }

    }

    However, note that the script is hard-coded, so you’ll need to change the test values (the co

    maybe even add or remove cases as necessary for your spreadsheet.

    Conclusion

     As you can see, scripts can be extremely useful in Google Spreadsheet. They tend to be ver

  • 8/17/2019 Boost Productivity With These Excellent Google Spreadsheet Scripts

    7/7

    http://www.makeuseof.com/tag/boost-productivity-with-these-excellent-google-spreadsheet-scripts/ Created with PrintWhatYouLike.com

    Sign up for more tips and awesome articles

    E-mail

    plan on using one that doesn’t come from the Script Gallery, there’s a high chance that you’

    However, Google has plenty of resources and tutorials (https://developers.google.com/apps

    have everything you need to do the job.

     That being said, don’t be afraid to check out the Script Gallery found under the Tools men

    do a lot for your day to day productivity. Ryan also showed us some amazing Google Sprea

    (http://www.makeuseof.com/tag/useful-google-spreadsheet-functions/). Using Google For

    (http://www.makeuseof.com/tag/10-advanced-tips-tricks-for-google-forms/) is a power-tas