How to Convert an Excel XLSX Spreadsheet to an HTML Document using Go
The main reason for converting your Excel spreadsheet (or any document) to HTML is straightforward: it turns your document into a static web page which can be viewed easily on any web browser at any time. Our XLSX to HTML API makes it possible to take control of that conversion and incorporate it into your application for use at scale, ensuring you won’t need to worry about manual format conversions in the future. Below, I’ve provided brief instructions to help you structure your XLSX to HTML API call in Go (for code examples in additional programming languages such as C#, Java, Node.js, etc., visit our documentation page). Before you get to that stage, however, you’ll want to make sure you have a Cloudmersive API key handy to authenticate the service; you can get one by registering a free account on our website (free accounts will provide a limit of 800 API calls per month with no additional commitments).
To call the function, simply copy & paste the below code examples into your file, and then configure your file path & API Key inputs as directed by the code comments:
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))
}
And just like that, you’re finished — no more code required. Fast & easy!