three Remarkable Google Docs Scripts to Automate Your Files

Download 3 Impressive Google Docs Scripts to Automate Your Documents For PC Now

There are several excellent explanations you really should be applying cloud-based Google Docs instead than software-based phrase processing applications like Microsoft Phrase. A single of the most significant is that you can build some very practical automations applying strong Google Scripts.

Listed here are a few scripts that let you establish a document from user prompts, import Google Analytics into a Google Doc report, and build a document from a Google Sheet file.

1. Use Prompts to Make a Doc

If you ship out the very same e-mail often, an automated document template can seriously help you preserve time. This could be some thing like a month-to-month product sales report to your supervisor, or weekly updates to colleagues. Something you create up often can be automated with a document template and a Google Script.

The 1st phase is developing a document template. Accomplishing this is as simple as developing a Google Doc. For the words you’d like to fill in, just surround them with two ## indications, like the case in point underneath.

Inside this document, you can build a Google Script that runs when the document opens. Your script will prompt you to enter every single of the aspects that go into the document.

To build your script, click on the Applications menu item, and click on Script editor.

docs script editor

In the editor window, delete the code that’s there and change it with the pursuing script.

This script will contact up prompts when the document opens, build a new document with the title of the product sales individual and today’s date in the title. Then it’ll fill in the template fields with the data you’ve entered.

functionality myFunction() 
  // Exhibit a dialog box for every single industry you need data for.
  
  var ui = DocumentApp.getUi()
  //var reaction = ui.prompt('Enter Name', 'Enter product sales person's name', ui.ButtonSet.Alright)
  var nameResponse = ui.prompt('Enter product sales folks name')
  var client1Response = ui.prompt('Enter shopper 1')
  var sales1Response = ui.prompt('Enter product sales 1')
  var client2Response = ui.prompt('Enter shopper 2')
  var sales2Response = ui.prompt('Enter product sales 2')
  var client3Response = ui.prompt('Enter shopper 3')
  var sales3Response = ui.prompt('Enter product sales 3')
  var commissionResponse = ui.prompt('Enter commission')
  var date = new Date()
    
  //Make a duplicate of the template file
  var documentId = DriveApp.getFileById('').makeCopy().getId()
      
  //Rename the copied file
  DriveApp.getFileById(documentId).setName(nameResponse.getResponseText() + date + ' Income Report')  
      
  //Get the document overall body as a variable
  var overall body = DocumentApp.openById(documentId).getBody()
    
  //Insert the entries into the document
  overall body.replaceText('##title##', nameResponse.getResponseText())
  overall body.replaceText('##client1##', client1Response.getResponseText())
  overall body.replaceText('##sales1##', sales1Response.getResponseText()) 
  overall body.replaceText('##client2##', client2Response.getResponseText())
  overall body.replaceText('##sales2##', sales2Response.getResponseText())  
  overall body.replaceText('##client3##', client3Response.getResponseText())
  overall body.replaceText('##sales3##', sales3Response.getResponseText())
  overall body.replaceText('##commission##', commissionResponse.getResponseText())

Switch the document ID code in the script above with the document ID of the template document.

You’ll find this embedded in the URL when you’re modifying the template document.

document id

In the Google Script editor window, click the diskicon to preserve the script.

Next, click on the runicon to check that it operates.

When you run the script for the 1st time, you might need to approve permissions for your Google Account to run the script.

Back in the template document, you will see the prompt windows pop up one right after the other. Fill in the fields with the details you want to go into the document.

google doc prompts

When you’re finished, the script will build a new document in your Google Push root folder with all of the data you’ve entered crammed in.

google docs new document

Ultimately, you just need to established up the script to run each time you open the template document.

In the Google Script Editor window, click on Edit > Current project’s triggers.

Simply click on the Include Induce button in the decrease right corner. Make confident Decide on function type is On open.

on open trigger

Scroll down and click Help save, and you’re finished.

2. Import Google Analytics Into a Doc Report

Regardless of whether you very own a web site, or you function for another person who owns one, a regular need is to measure web site traffic and overall performance


The seven Ideal Sites to Track a Website’s Targeted visitors




The seven Ideal Sites to Track a Website’s Targeted visitors

Listed here are some equipment that help you see how several people go to a web site, which you can use to review web site traffic studies.
Read More

and deliver it inside a formatted report.

You can use the very same template tactic as the part above to export web site details from Google Analytics and output it to a very well-formatted Google Docs report.

Initial, build a report template just like you did in the preceding part. In this case in point the template will be established up to deliver whole end users, sessions, and pageviews for the earlier week.

analytics report template

Next, go into the Google Docs Script Editor applying the very same steps as the preceding part.

Enable access to Google Analytics details by pursuing the steps underneath.

  1. In the script editor window, select Methods, and then Highly developed Google providers
  2. Simply click on/off following to Google Analytics API
  3. Underneath the dialog, click the Google Cloud Platform API Dashboard hyperlink
  4. In the Cloud Platform window, click on Enable APIs and Companies
  5. Look for for Analytics, and click on Analytics API
  6. Simply click on the Enable button to enable this API for your script
  7. Go again to the script editor window and click Alright to near the Highly developed Google Companies window

analytics api

Now that you’ve enabled integration with the Google Analytics API, you’re all set to mechanically build your report.

Paste the pursuing code inside the script editor code window.

functionality myFunction() 
  var tableId = 'ga:'
  var startDate = getLastNdays(seven)   // 1 week in the past.
  var endDate = getLastNdays()
  var date = new Date()
  
  var results = Analytics.Details.Ga.get(
      tableId,
      startDate,
      endDate,
    'ga:end users,ga:sessions,ga:pageviews',
      'dimensions': 'ga:date')

  var details = []
  var totals = results.totalsForAllResults
    for (metricName in totals) 
      details.press(totals[metricName])
  
  
  var end users = details[]

  var sessions = details[1]

  var pageviews = details[2]
  
  // Output to Google Doc.

  //Make a duplicate of the template file
  var documentId = DriveApp.getFileById('').makeCopy().getId()
  
  //Rename the copied file
  DriveApp.getFileById(documentId).setName(date + ' Web-site Report')
  
  //Get the document overall body as a variable
  var overall body = DocumentApp.openById(documentId).getBody()
  
  //Insert the entries into the document
  overall body.replaceText('##startdate##', startDate)
  overall body.replaceText('##enddate##', endDate)
  overall body.replaceText('##end users##', end users) 
  overall body.replaceText('##sessions##', sessions)
  overall body.replaceText('##pageviews##', pageviews)


functionality getLastNdays(nDaysAgo) 
  var right now = new Date()
  var just before = new Date()
  just before.setDate(right now.getDate() - nDaysAgo)
  return Utilities.formatDate(just before, 'GMT', 'yyyy-MM-dd')

Switch the document ID code in the script above with the document ID of the template document. Also change the Analytics ID with the ID displayed for your web site in Google Analytics.

In the Google Script editor window, click the disk icon to preserve the script.

Simply click on the run icon to check that it operates.

When you run the script for the 1st time, you will have to approve permissions for your Google Account to run the script.

Functioning the script will build a new document in your Google Push root folder with all of the web site overall performance data for the past week crammed in.

automated analytics report

Ultimately, you just need to established up the script to run each week.

In the Google Script Editor window, click on Edit and Current project’s triggers.

Simply click on the Include Induce button in the decrease right corner. Transform Decide on function supply to Time-driven. Transform Decide on type of time based bring about to Week timer.

google scripts weekly trigger

Scroll down and click Help save, and your script will run each week and build a new weekly report.

three. Produce a Doc From a Google Sheet

There are situations when you need to transfer data from a spreadsheet into a document, for factors like producing experiences or logging data.

If you find oneself doing this often, you can preserve time by integrating Google Sheets with Google Docs. For this script, you’re heading to use the Google Scripts Editor inside of Google Sheets, considering that that’s in which the details will appear from.

Initial, you’re heading to build your template product sales document just as you did in the 1st part of this write-up, embedding variables surrounded by the ## image.

google docs template

The details for these experiences will appear from your Google Sheets spreadsheet, which might look some thing like this case in point.

google sheets data

To build your script, inside of Google Sheets, click on the Applications menu item, and click on Script editor.

Paste the pursuing script in the editor script window.

functionality myFunction() 
  var date = new Date()

  // Opens SS by its ID
  var ss = SpreadsheetApp.openById("")

  var sheet = ss.getSheetByName('Sam') // or no matter what is the title of the sheet 

  //Make a duplicate of the template file
  var documentId = DriveApp.getFileById('').makeCopy().getId()
  
  //Rename the copied file
  DriveApp.getFileById(documentId).setName('Sam ' + date + ' Income Report')  
  
  //Get the document overall body as a variable
  var overall body = DocumentApp.openById(documentId).getBody()

  var range = sheet.getRange("A2:B4")

  overall body.replaceText('##title##', 'Sam')

  for (var i=1 i<4 i++) 
    cell = range.getCell(i,1)
    client = cell.getValue() 
    body.replaceText('##client' + i + '##', client)
    cell = range.getCell(i,2)
    sales = cell.getValue()
    body.replaceText('##sales' + i + '##', sales)

Switch the document ID in the script above with the document ID of the template document. Also change the Google Sheet ID with the ID of your details Google Sheet.

In the Google Script editor window, click the disk icon to preserve the script.

Simply click on the runicon to check that it operates.

Recall, when you run the script for the 1st time, you will need to approve permissions so it can access your Google Account.

When you run the script, it’ll build a new document in your Google Push root folder with all of the product sales data from the spreadsheet.

sales data document

It is also attainable to cycle through the sheet tabs and build a new product sales output document for each product sales individual on your workforce.

Why not enjoy around with the script above and see if you can pull this off?

Applying Google Scripts and Google Docs

Google Docs appears to be like a simple phrase processor, but as you can see when you integrate Google Analytics, it multiplies the functionality of this cloud app.

Templates in Google Docs are a core element of what will make all of this function. You’d be shocked just how substantially applying templates in Google Docs


24 Google Docs Templates That Will Make Your Everyday living Less complicated




24 Google Docs Templates That Will Make Your Everyday living Less complicated

Templates can preserve you plenty of time. We compiled 24 time-saving Google Docs templates for function, wellbeing, residence, and vacation. Get on with your tasks, instead than battling with placing together documents.
Read More

can make every little thing you do substantially more productive. Try out them out, and though you’re at it incorporate your very own innovative Google Script automations as very well.

Take a look at more about: Google Docs, Google Script, Google Sheets.

Tags: