Excel and Google Sheets as clients
Updated 2026-11-13
How to call a published service from a cell in Excel or Google Sheets: with one formula, with Power Query, or with a small custom function. The snippets for your own service are under API → Code → Excel and API → Code → Google Sheets.
When this is useful
Your calculation lives in one protected workbook on the server, and colleagues or customers use its results inside their own spreadsheets. They send inputs and get outputs; they never see the workbook or its formulas.
The examples use a service with the inputs amount and rate. Copy the versions for your service from API → Code; they already contain your address and input names.
Excel: one formula with WEBSERVICE
WEBSERVICE fetches an address and returns the answer as text. With _format=plain the service answers one line per output, name: value.
=WEBSERVICE("https://spreadapi.io/api/v1/services/{serviceId}/execute?amount=20000&rate=0.05&_format=plain")With the inputs in cells B1 and B2:
=WEBSERVICE("https://spreadapi.io/api/v1/services/{serviceId}/execute?" & "amount=" & B1 & "&rate=" & B2 & "&_format=plain")The cell then holds, for example, interest: 1000.
Notes:
WEBSERVICEexists in Excel 2013 and newer on Windows. In a German Excel the function is calledWEBDIENST.- The result is text. In Excel 365,
=VALUE(TEXTAFTER(A1, ": "))turns a singlename: valueline into a number. - Numbers in the address need a point as decimal separator. If your Excel writes
0,05, wrap the cell:SUBSTITUTE(B2, ",", "."). - The short address
https://spreadapi.run/{serviceId}keeps formulas shorter; see Call a service over the API.
Excel: a table with Power Query
Power Query reads the JSON answer and returns a table with the columns name, title and value. The values keep their type, so numbers arrive as numbers.
- In Excel choose Data > Get Data > From Other Sources > Blank Query.
- Open the Advanced Editor.
- Paste the query and confirm.
let
Source = Json.Document(
Web.Contents(
"https://spreadapi.io/api/v1/services/{serviceId}/execute",
[Query = [amount = "20000", rate = "0.05"]]
)
),
Outputs = Table.FromRecords(Source[outputs])
in
OutputsRefresh the query to calculate again.
Google Sheets: one formula with IMPORTDATA
IMPORTDATA reads CSV. With _format=csv the service answers two rows: the output names, then the values.
=IMPORTDATA("https://spreadapi.io/api/v1/services/{serviceId}/execute?amount=20000&rate=0.05&_format=csv")The formula fills a small range: the first row holds the names, the second row the values.
Google Sheets: a custom function
A custom function sends a POST and returns one row per result, name and value.
- In the sheet choose Extensions > Apps Script.
- Paste the function from API → Code → Google Sheets and save.
- Use it in a cell.
function SPREADAPI(serviceId, ...pairs) {
const inputs = {};
for (let i = 0; i + 1 < pairs.length; i += 2) inputs[pairs[i]] = pairs[i + 1];
const response = UrlFetchApp.fetch('https://spreadapi.io/api/v1/services/' + serviceId + '/execute', {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify({ inputs: inputs }),
muteHttpExceptions: true,
});
const data = JSON.parse(response.getContentText());
if (response.getResponseCode() !== 200) return [['Error', data.message || data.error]];
return data.outputs.map(function (output) { return [output.name, output.value]; });
}=SPREADAPI("{serviceId}", "amount", 20000, "rate", 0.05)The arguments after the service ID are input names and values, alternating. They can be cell references. When a call fails, the function returns a row with Error and the reason.
Token-protected services
- In the formulas, add the token to the address:
&token=YOUR_TOKEN_HERE. In Power Query, addtoken = "YOUR_TOKEN_HERE"to theQueryrecord. - In the Apps Script function, add
headers: { Authorization: 'Bearer YOUR_TOKEN_HERE' },to the options. The snippet in the app already has this line for a protected service.
A token in a cell formula is visible to everyone who can open the file. Give such a file its own token, so you can revoke it without affecting other callers; see Tokens and access.
Limits and tips
- CSV and plain text are made for single-cell outputs. For cell ranges use Power Query or the custom function, which read JSON.
- Send percentages as decimals:
0.05for 5%. See Percentages and formats. - An identical address may be answered from a stored result for a few minutes. Add
&nocache=truewhen the sheet must always get a new calculation; see Caching and performance. - Every recalculation of a formula is a call and counts toward the plan's calls. Sheets that recalculate often can use many calls; see Call limits.
- Text values with spaces or special characters must be URL-encoded in a formula. Excel and Google Sheets both have
ENCODEURL(B3)for this. _formatworks on GET only. An error is answered as JSON even when CSV or plain text was asked for.
Related
- The API response
- Import from Google Sheets, for bringing a sheet in as the workbook of a service
- Choose your way
For developers and agents
| Client | Request | Answer |
|---|---|---|
Excel WEBSERVICE | GET with inputs in the query and _format=plain | text/plain, one line per output: name: value |
| Excel Power Query | GET with inputs in the query, JSON | Table from outputs: name, title, value |
Sheets IMPORTDATA | GET with inputs in the query and _format=csv | text/csv, line 1 output names, line 2 values |
| Sheets custom function | POST {"inputs": {...}} | Rows of [name, value] |
On GET, a value that is not a valid number for a number input answers 400 with Parameter validation failed; the detail reads Expected a number, got: ....
FAQ
How do I call my service from Excel?
Use =WEBSERVICE("...&_format=plain") with the service address for a quick formula, or Power Query for a table of results. Both snippets for your service are under API → Code → Excel.
How do I call my service from Google Sheets?
Use =IMPORTDATA("...&_format=csv") with the service address, or the SPREADAPI custom function from API → Code → Google Sheets.
WEBSERVICE returns text like "interest: 1000". How do I get the number?
In Excel 365 use =VALUE(TEXTAFTER(A1, ": ")) on the cell. For several outputs or for older Excel versions, Power Query returns the values as a table.
Why does my Excel formula answer "Expected a number, got: 0,05"?
Your Excel wrote the number with a decimal comma into the address. Wrap the cell in SUBSTITUTE(B2, ",", ".") so the service receives 0.05.
Does WEBSERVICE work on a Mac or in Excel for the web?
WEBSERVICE is a function of Excel for Windows, from Excel 2013 on. On other versions use Power Query where it is available, or call the service from Google Sheets.
Where do I put the token in a spreadsheet formula?
Add &token=YOUR_TOKEN_HERE to the address. Everyone who can open the file can read it there, so use a separate token for that file.
My sheet shows the same result although the service changed. Why?
An identical address can be answered from a stored result for a few minutes. Add &nocache=true to the address to force a new calculation.
Can a formula return a whole table from my service?
Yes, with Power Query in Excel or the custom function in Google Sheets, which read the JSON answer. The CSV and plain-text formats are meant for single-cell outputs.
Does every recalculation of my sheet count as a call?
Yes. Each time the formula fetches the address, the service receives a call that counts toward the plan.
As an agent, which format should I pick for a spreadsheet client?
Use _format=plain for Excel WEBSERVICE, _format=csv for Google Sheets IMPORTDATA, and JSON for Power Query or Apps Script. Keep inputs in the query string and write decimals with a point.