代码拉取完成,页面将自动刷新
package excelT
import (
"fmt"
"strconv"
"gitee.com/Jiudan0905/go-tools/baseT/collection/sliceT"
)
func RowsToJson(rows []*Row) []map[string]string {
// 默认第一列是标题栏
var keyList []string
for _, cell := range rows[0].CellList {
if sliceT.ContainStr(cell.Value, keyList) {
panic("标题栏重复")
} else {
keyList = append(keyList, cell.Value)
}
}
// 默认第二列开始是数据
var dataList []map[string]string
for rowIndex, row := range rows[1:] {
if rowIndex%400 == 0 {
fmt.Println(fmt.Sprintf("ToJson: Row Just : %d", rowIndex))
}
tempMap := make(map[string]string)
tempMap["data.id"] = strconv.Itoa(rowIndex)
for i, cell := range row.CellList {
if i >= len(keyList) {
continue
}
tempMap[keyList[i]] = cell.Value
}
dataList = append(dataList, tempMap)
fmt.Println(tempMap)
}
return dataList
}
func RowsToJsonByKey(rows []*Row, keys ...string) map[string]map[string]string {
// 默认第一列是标题栏
var keyList []string
for _, cell := range rows[0].CellList {
if sliceT.ContainStr(cell.Value, keyList) {
panic(fmt.Sprintf("标题栏重复 %s", cell.Value))
} else {
keyList = append(keyList, cell.Value)
}
}
// 默认第二列开始是数据
dataList := make(map[string]map[string]string)
for rowIndex, row := range rows[1:] {
tempMap := make(map[string]string)
tempMap["data.id"] = strconv.Itoa(rowIndex)
for i, cell := range row.CellList {
if i >= len(keyList) {
continue
}
tempMap[keyList[i]] = cell.Value
}
for _, key := range keys {
if _, ok := tempMap[key]; !ok {
panic("Key不存在")
}
dataList[tempMap[key]] = tempMap
}
}
return dataList
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。