Skip to content

Instantly share code, notes, and snippets.

@mickelsonm
Created October 9, 2017 01:35
Show Gist options
  • Save mickelsonm/3984656ce1cc714c1e8aa977e7ef8fb9 to your computer and use it in GitHub Desktop.
Save mickelsonm/3984656ce1cc714c1e8aa977e7ef8fb9 to your computer and use it in GitHub Desktop.
router.HandleFunc("/import", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "error: invalid method", http.StatusBadRequest)
return
}
edata, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Printf("Error reading request body: %v\n", err)
http.Error(w, "error: reading file", http.StatusInternalServerError)
return
}
efile, err := xlsx.OpenBinary(edata)
if err != nil {
log.Printf("Error opening binary: %v\n", err)
http.Error(w, "error: opening excel file", http.StatusInternalServerError)
return
}
sheet := efile.Sheets[0]
toJSON(w, sheet.Rows)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment