Golang encoding/csv.Writer.WriteAll() function example
package encoding/csv
WriteAll writes multiple CSV records to w(given input type) using Write and then calls Flush.
Golang encoding/csv.Writer.WriteAll() function usage example
package main
import (
"encoding/csv"
"fmt"
"os"
)
func main() {
csvfile, err := os.Create("output.csv")
if err != nil {
fmt.Println("Error:", err)
return
}
defer csvfile.Close()
records := [][]string{{"item1", "value1"}, {"item2", "value2"}, {"item3", "value3"}}
writer := csv.NewWriter(csvfile)
err = writer.WriteAll(records) // flush everything into csvfile
if err != nil {
fmt.Println("Error:", err)
return
}
}
Reference :
See also : Golang encoding/csv.Writer.Write() function example
Advertisement
Something interesting
Tutorials
+9.7k Golang : Load ASN1 encoded DSA public key PEM file example
+28.8k Golang : Detect (OS) Operating System
+7.3k Golang : How to iterate a slice without using for loop?
+7.7k Golang : Command line ticker to show work in progress
+6.1k Java : Human readable password generator
+7.6k SSL : How to check if current certificate is sha1 or sha2 from command line
+17.9k Golang : How to make a file read only and set it to writable again?
+5.8k Golang : Launching your executable inside a console under Linux
+6.7k Golang : Output or print out JSON stream/encoded data
+18.3k Golang : Get path name to current directory or folder
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem