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
+6k PHP : How to check if an array is empty ?
+12.1k Golang : convert(cast) string to integer value
+4.4k Golang : Valued expressions and functions example
+5.6k Javascript : How to refresh page with JQuery ?
+14.4k Golang : How to convert a number to words
+18k Golang : Get all upper case or lower case characters from string example
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+22.1k Golang : Join arrays or slices example
+7.9k Javascript : Put image into Chrome browser's console
+9k Golang : Capture text return from exec function example
+11k Golang : Generate random elements without repetition or duplicate
+21.2k Golang : How to get time zone and load different time zone?