Exporting query results to Excel on macOS

Applies to

ApexSQL Database Power Tools for VS Code

Summary

This article describes the process of exporting query results to an Excel file (.xlsx) on macOS using the VS Code extension.

Description

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”:

Error exporting results to Excel: The type initializer for 'Gdip' threw an exception

Cause

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.

Resolution

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)”

Installation of Homebrew in a macOS Terminal

Hit Enter and then type the user account password to proceed with the installation.

Give it a few seconds to download and install Homebrew:

Successful Homebrew installation

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

Installing the Mono library that provides a GDI+-compatible API on non-Windows operating systems

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:

Successfully installed Mono library

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:

Save As dialog on Mac with download location and Excel file name specified

This time, it works like a charm and the query results are saved to the Excel file (.xlsx) as can be seen below:

Notification about successfully exported and saved data from the result set from VS Code extension

  • Tip: Click that Show button within the notification itself to open the file in Finder:

    Saved Excel file in Finder