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.9k Golang : Sort and reverse sort a slice of integers
+4.3k Golang : Converting individual Jawi alphabet to Rumi(Romanized) alphabet example
+9k Golang : Build and compile multiple source files
+8.3k Golang : Configure Apache and NGINX to access your Go service example
+11.7k Golang : Calculations using complex numbers example
+11.9k Golang : Convert decimal number(integer) to IPv4 address
+10.1k Golang : Identifying Golang HTTP client request
+23.9k Golang : Use regular expression to validate domain name
+6.1k PageSpeed : Clear or flush cache on web server
+11.3k Golang : Fix fmt.Scanf() on Windows will scan input twice problem
+13.4k Golang : Verify token from Google Authenticator App
+9.5k Golang : Extract or copy items from map based on value