Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Google Apps Script for Beginners

You're reading from  Google Apps Script for Beginners

Product type Book
Published in Feb 2014
Publisher
ISBN-13 9781783552177
Pages 178 pages
Edition 1st Edition
Languages
Author (1):
Serge Gabet Serge Gabet
Profile icon Serge Gabet

Table of Contents (16) Chapters

Google Apps Script for Beginners
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Enhancing Spreadsheets 2. Create and Manipulate Forms 3. Managing an E-mail Account 4. Embedding Scripts in Text Documents 5. Embedding Scripts in Google Sites 6. Standalone Web Applications / User Interfaces 7. Using User Interfaces in Spreadsheets and Documents 8. How to Expand your Knowledge 9. Conclusion Index

Printing and exporting the result


As of this writing (December 2013), Google Apps Script has no possible way to print a document. Printing all or part of a spreadsheet is a common activity, one that we might want to automate using a script. Unfortunately, security considerations limit Google Apps Script access to local resources such as printers.

As a workaround for this limitation, our script can export spreadsheets to PDF and send them by e-mail or store them in Google Drive.

A quick example that won't need too much explanation is as follows:

function sendThisSsAsPdf(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var ssID = ss.getId();// get the file unique id to use with driveApp
  var pdf = DriveApp.getFileById(ssID).getAs('application/pdf');//get the file content in PDF format
  var saveCopy = DriveApp.createFile(pdf);//create a copy in your drive
  MailApp.sendEmail(Session.getEffectiveUser().getEmail(),'This is a copy of your spreadsheet','This is a pdf copyof your spreadsheet as an attachment to this message\n'+
                    'This mail was sent to you on'+Utilities.formatDate(new Date(), Session.getTimeZone(),"MMM-dd-yyyy @ HH:mm"),{attachments : [pdf]});//send the email with a simple message
}

The preceding script shows how to simply and rapidly create a PDF version of the current spreadsheet and send it to the user at the keyboard; this function can be called from a menu of course, but can also be sent at a fixed time every single day if you need an archive copy for any reason.

In the next chapter, we'll see how to create and use Google forms as they are probably the second most-frequent entry point to Google Apps Script for most new users.

You have been reading a chapter from
Google Apps Script for Beginners
Published in: Feb 2014 Publisher: ISBN-13: 9781783552177
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}