package main
import (
"fmt"
"github.com/360EntSecGroup-Skylar/excelize/v2"
"gopkg.in/yaml.v2"
"io/ioutil"
"os"
)
func main() {
xlsx, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
rows, err := xlsx.GetRows("Sheet1")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
var data []map[string]string
for i, row := range rows {
if i == 0 {
continue
}
item := make(map[string]string)
for j, colCell := range row {
item[xlsx.GetCellValue("Sheet1", fmt.Sprintf("%s%d", excelize.ToAlphaString(j+1), i))] = colCell
}
data = append(data, item)
}
ymlData, err := yaml.Marshal(&data)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = ioutil.WriteFile("Book1.yml", ymlData, 0644)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
标签:xlsx,err,excelize,fmt,yaml,Exit,os
From: https://www.cnblogs.com/iXiAo9/p/17271409.html