Development

Create Dynamic Downloadable Documents using Google Sheets and Google Docs

By September 27, 2016 No Comments

Most of the websites that we develop include some form of downloadable PDF, XLSX, or DOC. These files might contain additional product information, pricing, or other specifications. Wouldn’t it be great to have the ability to update this information on-the-fly from the original source without having to re-upload the exported file? Today, I’m going to show you a very simple way to create dynamic downloadable documents within Google Sheets and Google Docs. Let’s get started.

1. Create your spreadsheet or document

For this example, I’m going to be creating a simple price sheet which includes a product name, description, SKU, and price. Let’s look at in Google Sheets.

Google Sheet screenshot

 

Now, what I would like to do is create a PDF from this spreadsheet. Perhaps your first thought might be that I should select the File menu and choose the ‘Download as’ option. While this will work, let’s automate this export process.

2. Update your share setting

Click the Share button in the upper right-hand corner of the page

Share button screenshot

Click the Get shareable link

Select the option “Anyone with the link can view

Share settings in Google Sheets

Copy the link. Here’s what my link looks like

https://docs.google.com/spreadsheets/d/1J97B-Id_Gf0iUNl7fTc1N2YcKqdwmxoxo0gXq_3Hih4/edit?usp=sharing

This will link directly to my spreadsheet in the view state. *NOTE – Make sure your document is set to ‘can view’ and NOT  ‘can edit’. Otherwise, the user will be able to modify your data.

3. Create the dynamic export link

Lets create an export link using the following logic.

For Spreadsheets:

https://docs.google.com/spreadsheets/d/YOUR_FILE_ID/export?format=xlsx https://docs.google.com/spreadsheets/d/YOUR_FILE_ID/export?format=pdf

For Documents:

https://docs.google.com/document/d/YOUR_FILE_ID/export?format=doc https://docs.google.com/document/d/YOUR_FILE_ID/export?format=pdf
https://docs.google.com/document/d/YOUR_FILE_ID/export?format=html
https://docs.google.com/document/d/YOUR_FILE_ID/export?format=txt
https://docs.google.com/document/d/YOUR_FILE_ID/export?format=odt

The File ID is accessible from the previously copied link. In my example the ID would be 1J97B-Id_Gf0iUNl7fTc1N2YcKqdwmxoxo0gXq_3Hih4

If I would like to create a PDF from my spreadsheet, this is the link that I would use.

https://docs.google.com/spreadsheets/d/1J97B-Id_Gf0iUNl7fTc1N2YcKqdwmxoxo0gXq_3Hih4/export?format=pdf

Finally, let’s add in a redirect so that if the user visited http://www.example.com/pricing they would be redirected to this dynamic download.

And there you have it! Simple and powerful!

Web Application Startup Guide

A 30-page ebook that covers positioning, marketing, pricing, and building your startup product, plus more.