Here’s an example of an OfficeScript that makes an API GET request to a dummy JSON API site and prints the values to an Excel range:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.
To use this OfficeScript, follow these steps:
- Open Excel Online or Excel for the web.
- Open an existing workbook or create a new workbook.
- Click on the “Automate” tab in the ribbon.
- Click on the “Script Lab” button.
- In the Script Lab pane, create a new script or open an existing one.
- Replace the default code in the script editor with the code provided above.
- Click the “Run” button to execute the script.
This script makes a GET request to the “https://jsonplaceholder.typicode.com/posts” API endpoint, which returns a dummy JSON data set. The response is parsed as JSON, and the id
and title
values are extracted from each item. The data is then printed to the range starting from cell A1 in the active worksheet.
Please note that OfficeScripts are currently only supported in Excel for the web and Excel Online. They are not available in the desktop version of Excel. Additionally, the fetch
function is used to make the API request, which is an asynchronous function and requires the await
keyword to handle the response.