How to Convert Excel XLSX Files to CSV in C/C++

Cloudmersive
2 min readJul 27, 2023

--

While Excel data appears similar to tabular CSV format at a glance, XLSX format is actually XML (Office OpenXML) based on account of the dozens of complex features available through the Excel application. Converting Excel to CSV can be done manually via the Excel file management tab, and it can be done programmatically using relevant libraries. The below code allows you to accomplish a quick XLSX to CSV conversion through a free & extremely quick API request, returning data from each worksheet in your Excel file as its own CSV object.

To make an API call using C/C++ code, start by installing libcurl:

libcurl/7.75.0

After that, copy the below code to structure your request, and provide a free-tier API key in the API key authorization header:

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/csv/multi");
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, "outputEncoding: <string>");
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 a free-tier API key, you’ll be able to perform up to 800 conversions per month with no commitment upon reaching that limit. Now you can easily command Excel XLSX to CSV conversions at scale and incorporate this service into any of your C/C++ file processing applications.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet