WriteCSV WriteCSV writes a table to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg). If headers = true then generate column headers that capture the type and tensor cell geometry of the columns, enabling full reloading of exactly the same table format a
(w io.Writer, delim Delims, headers bool)
| 394 | // of exactly the same table format and data (recommended). |
| 395 | // Otherwise, only the data is written. |
| 396 | func (dt *Table) WriteCSV(w io.Writer, delim Delims, headers bool) error { |
| 397 | ncol := 0 |
| 398 | var err error |
| 399 | if headers { |
| 400 | ncol, err = dt.WriteCSVHeaders(w, delim) |
| 401 | if err != nil { |
| 402 | log.Println(err) |
| 403 | return err |
| 404 | } |
| 405 | } |
| 406 | cw := csv.NewWriter(w) |
| 407 | cw.Comma = delim.Rune() |
| 408 | for ri := 0; ri < dt.Rows; ri++ { |
| 409 | err = dt.WriteCSVRowWriter(cw, ri, ncol) |
| 410 | if err != nil { |
| 411 | log.Println(err) |
| 412 | return err |
| 413 | } |
| 414 | } |
| 415 | cw.Flush() |
| 416 | return nil |
| 417 | } |
| 418 | |
| 419 | // WriteCSV writes only rows in table idx view to a comma-separated-values (CSV) file |
| 420 | // (where comma = any delimiter, specified in the delim arg). |