package main
import (
"fmt"
"strings"
"github.com/xuri/excelize/v2"
)
func main() {
f, err := excelize.OpenFile("Book1.xlsx")
if err != nil {
fmt.Println(err)
return
if err = f.Close(); err != nil {
fmt.Println(err)
}
}
func getCellBgColor(f *excelize.File, sheet, axix string) string {
styleID, err := f.GetCellStyle(sheet, axix)
if err != nil {
return err.Error()
}
fillID := *f.Styles.CellXfs.Xf[styleID].FillID
fgColor := f.Styles.Fills.Fill[fillID].PatternFill.FgColor
if fgColor != nil {
if fgColor.Theme != nil {
dklt := map[int]string{
0: children[1].SysClr.LastClr,
1: children[0].SysClr.LastClr,
2: *children[3].SrgbClr.Val,
3: *children[2].SrgbClr.Val,
}
return strings.TrimPrefix(
excelize.ThemeColor(dklt[*fgColor.Theme], fgColor.Tint), "FF")
}
srgbClr := *children[*fgColor.Theme].SrgbClr.Val
return strings.TrimPrefix(excelize.ThemeColor(srgbClr, fgColor.Tint), "FF")
}
return strings.TrimPrefix(fgColor.RGB, "FF")
}