How to Convert Excel XLSX to HTML using C/C++
Excel documents stored in HTML format can be opened and viewed on any internet browser (increasing their accessibility), and their contents can also be reformatted and displayed using advanced HTML features. To make that conversion possible, you’ll just need the right library — or the right API.
Using the below code examples, you can easily incorporate a free Excel to HTML conversion API in C/C++. Just follow brief instructions to structure your request, provide a free-tier API key in the authorization header, and you’re good to go.
First things first, install libcurl in your C/C++ project:
libcurl/7.75.0
After that, structure your API call using the following ready-to-run code:
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/html");
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 now convert your documents via their file path and write the resulting HTML string to a file of its own.