Method of exporting content to Excel in the Go language
- 2020-05-12 02:46:36
- OfStack
This article illustrates how the Go language exports content to Excel. Share with you for your reference. The specific implementation method is as follows:
package main
import (
"os"
"encoding/csv"
)
func main() {
f, err := os.Create("haha2.xls")
if err != nil {
panic(err)
}
defer f.Close()
f.WriteString("\xEF\xBB\xBF") // write UTF-8 BOM
w := csv.NewWriter(f)
w.Write([]string{" Serial number "," The name "," age "})
w.Write([]string{"1"," zhang 3","23"})
w.Write([]string{"2"," li 4","24"})
w.Write([]string{"3"," The king 5","25"})
w.Write([]string{"4"," zhao 6","26"})
w.Flush()
}
I hope this article has been helpful to your programming of Go language.