Standard library / encoding/csv

encoding/csv.Writer.WriteAll()

Write all records and flush the buffer, returning any encountered error. The caller must still handle a destination file close error if applicable. Expected stdout: 'a,b\nc,d\n'.

Formal Syntax & Structure

go syntaxgo
func (w *Writer) WriteAll(records [][]string) error

Parameters & Attributes

NameTypeDescription
records[][]stringCSV records in order.

Return Value

error

Nil on success; otherwise an operation-specific error.

Working Example

Example Snippetgo
package main
import (  "bytes"  "encoding/csv"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var b bytes.Buffer  w := csv.NewWriter(&b)  must(w.WriteAll([][]string{{"a", "b"}, {"c", "d"}}))  fmt.Print(b.String())}
Go Reference