Tour de force

WooExpert Platinum WooCommerce partner - biggest elephant in the eCommerce room.
Mailchimp Partner Mailchimp partner - you know what’s the newest cutting edge customer experience solution? Great email subject!
Clutch logo Clutch - clients say we’re top dogs in eCommerce. Throw us that stick now.
WordPress Vip WordPress VIP - Enterprise hosting partner

Import real time exchange rates currency into GOOGLE APPS spreadsheet

This tutorial shows how you can import currency exchange rates into your Google Apps spreadsheet in real-time through JSON online service

Listen to this article
1x
0.5x 0.75x 1x 1.25x 1.5x

If you are doing business analysis or calculations in your Google Apps spreadsheets then you probably need some kind of currencies converter for doing all sorts of tasks…

  • Convert your revenue from Dollars to Euros
  • Currency Risk analysis
  • Managing your expenses in one or multiple exchange rates
  • ….

One might guess that Google supports Exchange rates in their spreadsheets “AS-IS” but this is not the case. Also, their labs service Google Finance is deprecated so we must get our hands dirty and take the JavaScript approach for populating our spreadsheet with REAL-TIME currency quotes.

The first thing is to find the source of our data and for this use-case, we decided to give OpenSource Exchange rates JSON data a green light. This service returns JSON formatted dates for all currencies and please note that the base currency is the US Dollar. If you click here you will see the example of JSON data…

Next, we need to create a script for our spreadsheet and we can do this task if we click on “Tools” -> “Script Manager”. FYI, scripting in Google spreadsheet is quite powerful and you can scan through entire documentation on official Google apps help portal

SpreadsheetScriptManager

Next, we need to set triggers on our new script to fire up when we open the spreadsheet! This step is performed through the user interface and the full documentation can also be found on Google help portal

When you’re done setting up triggers, navigate to the script editor section and write up JavaScript that is exactly the same as this one… :))

function myFunction()
{
  var response = UrlFetchApp.fetch("http://openexchangerates.org/latest.json");

  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("SheetName");

  var object = Utilities.jsonParse(response.getContentText());

  var objRates = object["rates"];

  for (var i in objRates)
  {
    if(i="HRK")
    {
      sheet.getRange(2, 1).setValue(objRates[i]);
    }

    if(i="EUR")
    {
      sheet.getRange(2, 2).setValue(objRates[i]);
    }
  }
}

Just change the “SheetName” to the name of the sheet where you want your data to show. Note that this script takes two currencies (Euro and Croatian Kuna) and places them in a given row/column layout. If you need some other currencies just add another IF statement and set some different range of the cell!

Blog update (14th July 2012): As the user WittZi stated … it is very easy right now to import currencies into the spreadsheet. Just use =GoogleFinance(“CURRENCY:EURUSD”) to get Euros to USD or something similar.
Krešimir Končić
Krešimir Končić Owner at Neuralab

Ex QBASIC developer that ventured into a web world in 2007. Leading a team of like-minded Open Source aficionados that love design, code and a pinch of BBQ. Currently writing a book that explains why ‘coding is the easier part’ of our field.


Subscribe to our quarterly newsletter

Please fill in this field.
Please thick this field to proceed.

Related blog posts