Convert an XLS Workbook to CSV in C/C++

File conversions are not the easiest processes to perform manually, especially when working with outdated formats such as the 97–2003 version of Excel. In this tutorial, we will demonstrate how you can simplify a conversion from XLS to the CSV format by using an API in C/C++.

Let’s begin by installing libcurl:


Then, we can call the ConvertXLStoCSV function with the following code:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "");
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);

To retrieve your API key for the operation, you can visit the Cloudmersive website and register for a free account; this will provide 800 monthly calls across any of our APIs.

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