mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-25 11:04:31 +00:00
28 lines
447 B
Go
28 lines
447 B
Go
package report
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/csv"
|
|
)
|
|
|
|
// CsvExport returns the report as character separated values.
|
|
func CsvExport(rows [][]string, cols []string, sep rune) (string, error) {
|
|
buf := &bytes.Buffer{}
|
|
writer := csv.NewWriter(buf)
|
|
|
|
if sep > 0 {
|
|
writer.Comma = sep
|
|
}
|
|
|
|
err := writer.Write(cols)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if err := writer.WriteAll(rows); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return buf.String(), nil
|
|
}
|