How to Convert Excel XLS (97–03) Spreadsheets to Modern Excel (XLSX) Format using Go
One of the biggest and most notable differences between XLS and XLSX (other than the obvious fact that one was designed for MS Office 97–03, and one is designed for Excel 2007 & onward) is the way each file extension stores data: the former is stored in a proprietary binary interchange format, while the latter is stored in a zipped Office XML format. While XLS is still usable within modern Excel applications, that binary interchange data poses an inherent security risk which — especially coupled with the unnerving fact that XLS files automatically run macros when the file is opened — makes XLSX much more desirable when handling sensitive professional data.
Thankfully, with the help of our XLS to XLSX conversion API, you can transition your files between these formats programmatically, averting the risk of opening potentially harmful legacy-format data on your machine. It’s simple & easy to use; you just need to follow brief instructions below to structure your API call in Go and register a free account on our website to get your API key (free-tier keys provide a limit of 800 API calls per month with no additional commitments).
To call this API, all you need to do is copy & paste the below code examples into your file. Then, you just need to configure your file path & API key inputs appropriately, and you’re all done:
package mainimport (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)func main() {url := "https://api.cloudmersive.com/convert/xlsx/to/html"
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))
}