func CreateCSV(drawIOHeader Header, headerRow []string, contents []map[string]string, filename string) {
	total := [][]string{}
	total = append(total, headerRow)
	for _, holder := range contents {
		values := make([]string, len(headerRow))
		for counter, key := range headerRow {
			if val, ok := holder[key]; ok {
				values[counter] = val
			}
		}
		total = append(total, values)
	}
	var target io.Writer
	if filename == "" {
		target = os.Stdout
	} else {
		file, err := os.Create(filename)
		if err != nil {
			log.Fatal(err)
		}
		defer file.Close()
		target = bufio.NewWriter(file)
	}
	buf := new(bytes.Buffer)
	fmt.Fprintf(buf, "%s", drawIOHeader.String())
	buf.WriteTo(target)
	w := csv.NewWriter(target)

	for _, record := range total {
		if err := w.Write(record); err != nil {
			log.Fatalln("error writing record to csv:", err)
		}
	}

	w.Flush()

	if err := w.Error(); err != nil {
		log.Fatal(err)
	}
}
// CreateCSV creates the CSV complete with the header
CreateCSV creates the CSV complete with the header
// CreateCSV creates the CSV complete with the header
func CreateCSV(drawIOHeader Header, headerRow []string, contents []map[string]string, filename string) {
	total := [][]string{}
	total = append(total, headerRow)
	for _, holder := range contents {
		values := make([]string, len(headerRow))
		for counter, key := range headerRow {
			if val, ok := holder[key]; ok {
				values[counter] = val
			}
		}
		total = append(total, values)
	}
	var target io.Writer
	if filename == "" {
		target = os.Stdout
	} else {
		file, err := os.Create(filename)
		if err != nil {
			log.Fatal(err)
		}
		defer file.Close()
		target = bufio.NewWriter(file)
	}
	buf := new(bytes.Buffer)
	fmt.Fprintf(buf, "%s", drawIOHeader.String())
	buf.WriteTo(target)
	w := csv.NewWriter(target)
	for _, record := range total {
		if err := w.Write(record); err != nil {
			log.Fatalln("error writing record to csv:", err)
		}
	}
	w.Flush()
	if err := w.Error(); err != nil {
		log.Fatal(err)
	}
}
func CreateCSV ( drawIOHeader Header , headerRow [ ] string , contents [ ] map [ string ] string , filename string ) { total := [ ] [ ] string { } total = append ( total , headerRow ) for _ , holder := range contents { values := make ( [ ] string , len ( headerRow ) ) for counter , key := range headerRow { if val , ok := holder [ key ] ; ok { values [ counter ] = val } } total = append ( total , values ) } var target io . Writer if filename == " " { target = os . Stdout } else { file , err := os . Create ( filename ) if err != nil { log . Fatal ( err ) } defer file . Close ( ) target = bufio . NewWriter ( file ) } buf := new ( bytes . Buffer ) fmt . Fprintf ( buf , " " , drawIOHeader . String ( ) ) buf . WriteTo ( target ) w := csv . NewWriter ( target ) for _ , record := range total { if err := w . Write ( record ) ; err != nil { log . Fatalln ( " " , err ) } } w . Flush ( ) if err := w . Error ( ) ; err != nil { log . Fatal ( err ) } }
CreateCSV creates the CSV complete with the header
CreateCSV creates the CSV complete with the header