How to Convert an Excel (XSLX) Spreadsheet to a PNG Image Array using Go
Converting spreadsheets to PNG format has a similar use case to the oft-used PDF conversion. In PNG format, your spreadsheet data is protected by raster graphics from unwanted downstream edits, and it’s also guaranteed compatibility with just about any operating system the world has to offer. Thankfully, making this conversion is simple: all you need to do is use our XLSX to PNG Image Array Conversion API, and you can rely on a built-in data conversion solution in the long term. This API will convert each worksheet from a single XSLX file into its own PNG image and subsequently return all of those images as a PNG array for your convenience.
To use this API, all you need to do is copy Go code examples provided below to structure your API call, and then authenticate your call with a Cloudmersive API key (you can get one for free by registering a free account on our website; free accounts come with a limit of 800 API calls per month).
package mainimport (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)func main() {url := "https://api.cloudmersive.com/convert/xlsx/to/png"
method := "POST"payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("/path/to/file")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("inputFile",filepath.Base("/path/to/file"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "multipart/form-data")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
After that, simply configure your file & API key inputs, and you’re good to go. Told you it was easy!