How to Convert an Excel XLSX File to a PNG Array using C/C++

Cloudmersive
2 min readJul 27, 2023

--

Much like multi-page PDF documents, PNG file arrays are lightweight, easily accessible on any device, and their contents can’t be readily changed/manipulated by casual document viewers. This all makes PNG an excellent format for sharing screen grabs of Excel spreadsheet data.

The below code conveniently allows you to capture PNG screenshots of each worksheet in an Excel XLSX file in one quick API request. The request accepts form data, so you can easily incorporate this operation into your file processing applications and convert files via their file path.

You’ll first need to install libcurl in your project:

libcurl/7.75.0

And after that you can copy the ready-to-run code examples below to structure your API call:

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

The response will contain the encoding for one PNG file per worksheet in the original document. You can make up to 800 free requests per month by providing a free-tier API key in the API key header.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet