How to Convert an Excel file to JSON in C/C++

While Excel files may be the go-to format for data management and organization, you can run into some issues in preserving the original function and quality of the data when attempting to transfer it to a web application. To avoid problems like these from delaying or injuring your goals, you can automatically convert an Excel file to the more online-friendly JSON format by using the following API in C/C++.

To use this API, we first need to install libcurl into your project:

libcurl/7.75.0

Following the installation, we can call the Excel to JSON conversion function:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/xlsx/to/json");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);

With this simple operation, you can optimize a spreadsheet for any web-based application or project. Visit the Cloudmersive website to retrieve your free API key; this will give you access to 800 monthly calls across our multitude of APIs.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store