1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-10 15:52:27 +08:00

fix: fix the map key order issue of WriteMapsToCsv

This commit is contained in:
dudaodong
2024-01-22 11:10:02 +08:00
parent ac2ecceaec
commit bbc58c7e46
7 changed files with 90 additions and 44 deletions

View File

@@ -3,6 +3,7 @@ package fileutil
import (
"fmt"
"io"
"log"
"os"
)
@@ -331,26 +332,26 @@ func ExampleWriteCsvFile() {
// [[Lili 22 female] [Jim 21 male]]
}
// func ExampleWriteMapsToCsv() {
// csvFilePath := "./testdata/test3.csv"
// records := []map[string]string{
// {"Name": "Lili", "Age": "22", "gender": "female"},
// {"Name": "Jim", "Age": "21", "gender": "male"},
// }
func ExampleWriteMapsToCsv() {
csvFilePath := "./testdata/test3.csv"
records := []map[string]any{
{"Name": "Lili", "Age": "22", "Gender": "female"},
{"Name": "Jim", "Age": "21", "Gender": "male"},
}
// err := WriteMapsToCsv(csvFilePath, records, false, ';')
err := WriteMapsToCsv(csvFilePath, records, false, ';')
// if err != nil {
// log.Fatal(err)
// }
if err != nil {
log.Fatal(err)
}
// content, err := ReadCsvFile(csvFilePath, ';')
content, err := ReadCsvFile(csvFilePath, ';')
// fmt.Println(content) //顺序不固定
fmt.Println(content)
// // Output:
// // [[Name Age gender] [Lili 22 female] [Jim 21 male]]
// }
// Output:
// [[Age Gender Name] [22 female Lili] [21 male Jim]]
}
func ExampleWriteStringToFile() {
filepath := "./test.txt"