- url - The url of the web service to call.
How to use
The WEBSERVICE function returns data from a web service hosted on the internet. The WEBSERVICE function is only available in Excel 2013 and later for Windows.
A web service uses a protocol like HTTP to retrieve data in a machine-readable format like XML or JSON. For example, a formula that uses WEBSERVICE to call a fictitious web service hosted at somewebservice.com might look something like this:
The result from the WEBSERVICE function is returned directly to the worksheet. In cases where the result from a webservice is in XML format, you can use the FILTERXML function to parse the XML.
A simple example of a web service is RSS, which is used to syndicate content in XML format. RSS is widely available and does not require authentication, so it is an easy way to test the WEBSERVICE function. In the example above, WEBSERVICE is used to fetch breaking news from NASA. The formula in B4 is:
RSS uses XML, so the result is a long string of XML that contains the titles of the last 10 news articles published by NASA, along with meta information like description, date, url, and so on. The screen below shows this data in a text editor:
Parsing the result
When the result from WEBSERVICE is XML, you can use the FILTERXML function to parse the data. In the example shown, this is how the data and title of each article is extracted. The formula in B7 extracts the date, and trims extra characters with the MID function to create an Excel-friendly date:
The formula in C7 extracts the title:
- When WEBSERVICE can't retrieve data, it returns a #VALUE! error.
- If the result from WEBSERVICE is more than 32767 characters, it returns a #VALUE! error.