# Spreadsheets

> Pull current CurrencyCore reference rates and conversions into Google Sheets and Excel with Apps Script or Power Query, plus caching, quotas, and troubleshooting.

Canonical: https://currency-core.com/docs/spreadsheets/
Updated: 2026-11-10
Published: 2026-06-04

---
You can call CurrencyCore from a spreadsheet. Every authenticated request needs
an `Authorization` header, so the built-in `IMPORTDATA` function in Google Sheets
and `WEBSERVICE` in Excel are not enough on their own. Use **Apps Script** in
Google Sheets and **Power Query** in Excel.

> Keep the key out of shared cells. In Sheets, store it in **Script Properties**.
> In Excel, store it with the query credentials. Use a [test key](/docs/authentication/)
> while you build.

## Google Sheets

Open **Extensions → Apps Script**, paste the code below, and save. Then open
**Project Settings → Script Properties** and add `CC_KEY` with your API key.

```js
/**
 * =CC_CONVERT("USD", "INR", 100)  -> converted amount
 * =CC_RATE("EUR", "USD")          -> 1 EUR in USD
 */
function CC_CONVERT(from, to, amount) {
  const data = ccFetch_(
    "/v1/convert?from=" + encodeURIComponent(from) +
    "&to=" + encodeURIComponent(to) +
    "&amount=" + encodeURIComponent(amount)
  );
  if (!data.results || !data.results[0]) {
    throw new Error("CurrencyCore returned no conversion result");
  }
  return data.results[0].result;
}

function CC_RATE(base, quote) {
  const data = ccFetch_("/v1/rates/" + encodeURIComponent(base));
  if (!data.rates || data.rates[quote] == null) {
    throw new Error("No rate for " + quote + " against " + base);
  }
  return data.rates[quote];
}

function ccFetch_(path) {
  const cache = CacheService.getScriptCache();
  const cached = cache.get(path);
  if (cached) return JSON.parse(cached);

  const key = PropertiesService.getScriptProperties().getProperty("CC_KEY");
  if (!key) throw new Error("Set CC_KEY in Script Properties");

  const res = UrlFetchApp.fetch("https://api.currency-core.com" + path, {
    headers: { Authorization: "Bearer " + key },
    muteHttpExceptions: true,
  });
  const code = res.getResponseCode();
  const text = res.getContentText();
  if (code < 200 || code >= 300) {
    let message = text;
    try {
      message = JSON.parse(text).error.message;
    } catch (_) {
      // Keep the raw body when it is not JSON.
    }
    throw new Error("CurrencyCore " + code + ": " + message);
  }
  cache.put(path, text, 300);
  return JSON.parse(text);
}
```

Use them:

```
=CC_CONVERT("USD", "INR", 100)
=CC_RATE("EUR", "USD")
```

`ccFetch_` caches each URL for **5 minutes**. That reduces quota use when a
sheet recalculates and keeps repeated cells from making the same request.
Google also caches custom-function results, so change an argument or reopen the
sheet to force a refresh. Do not call the functions thousands of times in a
tight loop.

### Apps Script limits

Apps Script stops a script run after **6 minutes**. A spreadsheet full of custom
functions can approach that limit if every cell makes a separate network call.
Keep formulas small, cache aggressively, and prefer one rates query per sheet
over one conversion per row.

Google also applies daily URL Fetch and trigger quotas to Apps Script. The exact
quotas depend on your Google account type. If a large sheet starts returning
quota errors, move the refresh into a time-driven trigger that writes values into
cells instead of recalculating formulas on every edit.

### Share a template, not a key

A safe template has the formulas and formatting but no credential. Each person
who copies it adds their own key under **Project Settings → Script Properties**.
Never put the key in a cell, a named range, or a comment. If a sheet is shared
with a contractor or made public, treat any key that was stored in it as leaked
and rotate it from the dashboard.

## Microsoft Excel (Power Query)

Go to **Data → Get Data → From Other Sources → Blank Query → Advanced Editor**
and paste this. It pulls every rate against a base currency into a table. Create
a Power Query parameter named `CC_KEY` (**Home → Manage Parameters**) and set it
to a test key. Do not put a live key in shared cells or commit it with the query.

```
let
  Key   = CC_KEY, // Power Query parameter holding a test key
  Base  = "USD",
  Json  = Json.Document(
    Web.Contents(
      "https://api.currency-core.com/v1/rates/" & Base,
      [ Headers = [ Authorization = "Bearer " & Key ] ]
    )
  ),
  Rates = Record.ToTable(Json[rates])
in
  Rates
```

`Rates` becomes a two-column table (`Name` is the currency, `Value` is the rate
per 1 unit of the base). Reference it from a cell with `XLOOKUP` or `VLOOKUP`.

To convert a single amount instead, query `/v1/convert`:

```
let
  Key  = CC_KEY, // Power Query parameter holding a test key
  Json = Json.Document(
    Web.Contents(
      "https://api.currency-core.com/v1/convert",
      [
        Query   = [ from = "USD", to = "INR", amount = "100" ],
        Headers = [ Authorization = "Bearer " & Key ]
      ]
    )
  )
in
  Json[results]{0}[result]
```

Refresh with **Data → Refresh All**, or set an automatic refresh interval in the
query properties. Store the key in the query credentials rather than in a cell
that other people can read.

## Troubleshooting

| Symptom | Likely cause | Fix |
|---|---|---|
| `#ERROR!` in a cell | The custom function threw. Common causes are a missing `CC_KEY`, a revoked key, an unknown currency, or a non-2xx response. | Open **Extensions → Apps Script → Executions** and read the error. Fix the key or the formula. |
| `#NAME?` | The function was not saved, or the formula is in a sheet without the bound script. | Save the Apps Script project, reload the sheet, and check the spelling of `CC_CONVERT` or `CC_RATE`. |
| `401 unauthorized` | The key is missing, revoked, or pasted with extra spaces. | Re-enter `CC_KEY` in Script Properties. Rotate the key if it was exposed. |
| `403 forbidden` | A live key is calling a data endpoint on the Free plan, or a historical date is outside the Free 30-day window. | Use a test key, upgrade, or query a recent date. |
| `429 rate_limited` | The per-minute limit or monthly quota was reached. | Wait for `Retry-After`, reduce formulas, and rely on the 5-minute cache. |
| `Service invoked too many times` or a URL Fetch quota error | Apps Script has hit a Google quota. | Reduce calls, increase caching, or move refreshes to a scheduled trigger. |
| `Authorization is required` | The script has not been authorized. | Run a function once from the Apps Script editor and approve the permissions. |
| Empty result or `#N/A` in Excel | The currency code is not in the returned rates map. | Check the code against [/currencies](/docs/currencies/). |
| Excel asks for credentials again | The query credentials were not saved with the workbook. | Re-enter the key in the query settings and save. |

Spreadsheet calls count toward your plan's monthly quota and per-minute rate
limit like any other request. Only successful requests count toward the monthly
quota; errors still count toward the per-minute window. See
[Rate Limits and Plan Quotas](/docs/rate-limits/).

Country codes for PPP are ISO/IMF alpha-3 codes, listed on
[/countries](/docs/countries/). For a no-code conversion, use the
[currency converter](/tools/currency-converter/).

## Related products

- [Pricing](/pricing/)
- [Currency API](/currency-api/)
- [MCP server](/mcp-server/)
- [Currency converter](/tools/currency-converter/)
- [Getting started](/docs/getting-started/)
