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
+22.7k Golang : How to validate URL the right way
+12.2k Golang : Set image canvas or background to transparent
+6.9k Golang : Add build version and other information in executables
+18.1k Golang : Count JSON objects and convert to slice/array
+18.4k Golang : How to count the number of repeated characters in a string?
+7.2k Golang : Ackermann function example
+21.9k Golang : Fix type interface{} has no field or no methods and type assertions example
+6.4k Golang : Detect sample rate, channels or latency with PortAudio
+11.2k Golang : Remove or trim extra comma from CSV
+10.8k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+8.7k PHP : Get coordinates latitude/longitude from string
+5.4k Golang : Embedded or data bundling example