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
+7.5k Golang : Handling Yes No Quit query input
+8.1k Golang : Tell color name with OpenCV example
+37.7k Golang : Comparing date or timestamp
+16.3k Golang : Find out mime type from bytes in buffer
+14.3k Golang : Simple word wrap or line breaking example
+13.9k Golang : Get current time
+20.8k Golang : Convert date string to variants of time.Time type examples
+10.9k Golang : Get UDP client IP address and differentiate clients by port number
+62.7k Golang : Convert HTTP Response body to string
+17.5k Golang : Clone with pointer and modify value
+12.7k Golang : Pass database connection to function called from another package and HTTP Handler
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)