How to Convert Excel XSLX to Text using C/C++

Cloudmersive
2 min readJul 26, 2023

--

Excel’s OpenXML format makes it possible to store tabular data and apply formatting changes with dozens upon dozens of powerful application features. When it’s just the plain-text content of an Excel document we’re after, however, it can be a bit difficult to extract the contents of our cells and rows at scale without wasting time pointing and clicking through file management tabs.

Thankfully, the below code makes it easy to extract text contents from Excel files using a free document conversion API. The underlying service separates text contents from OpenXML format, returning a plain-text string with all text contents contained within the document.

You can begin your API call by first installing libcurl in your C/C++ project:

libcurl/7.75.0

And then copying the ready-to-run code examples below to structure your request:

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/txt");
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);

You can authenticate your request by copying a free-tier Cloudmersive API key in the authentication header. These can be obtained on our website, and they allow up to 800 API calls per month with no commitment.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet