This article describes the process of exporting query results to an Excel file (.xlsx) on macOS using the VS Code extension.
Exporting query results is possible using the VS Code extension into several standard formats. One of those formats is Excel. The VS Code extension supports multiple operating systems. However, unlike Windows users, when using the Export to Excel feature on Mac, users might be presented with a message saying “Error exporting results to Excel: The type initializer for ‘Gdip’ threw an exception”:
This operation is unable to complete because of the missing .NET Core packages on Mac that are used by the VS Code extension for exporting query results to an Excel file.
Although the “fix” for overcoming this issue is pretty straight-forward, and it only requires installing the stuff extension needs that Apple didn’t, it does require running a few commands in Terminal on Mac. Don’t worry though, the following sections explain the process in just a few steps.
First things first, we need to open Terminal on Mac by doing one of the following:
- Click the Launchpad icon in the Dock, type “terminal” in the search field, then select Terminal
- Open Finder, go to Applications > Utilities folder, then double-click Terminal
Next, we will need to install Homebrew. Paste the following in the macOS Terminal:
/bin/bash -c “$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)”
Hit Enter and then type the user account password to proceed with the installation.
Give it a few seconds to download and install Homebrew:
Now it’s time to install GDI+-compatible API on non-Windows operating system, Libgdiplus.
Paste the following command in the macOS Terminal and run it:
brew install mono-libgdiplus
Give it a minute or two to download needed packages and to install them. You should see a message that the whole bash has been installed successfully:
Launch VS Code, run a query to fetch data and use the Export to Excel icon to export query results. In the newly opened dialog, give it a name, choose where to save it, and click that Save button:
This time, it works like a charm and the query results are saved to the Excel file (.xlsx) as can be seen below:
- For more information on how to install and use Homebrew, see their homepage