1. package main
    2. import (
    3. "fmt"
    4. "strings"
    5. "github.com/xuri/excelize/v2"
    6. )
    7. func main() {
    8. f, err := excelize.OpenFile("Book1.xlsx")
    9. if err != nil {
    10. fmt.Println(err)
    11. return
    12. if err = f.Close(); err != nil {
    13. fmt.Println(err)
    14. }
    15. }
    16. func getCellBgColor(f *excelize.File, sheet, axix string) string {
    17. styleID, err := f.GetCellStyle(sheet, axix)
    18. if err != nil {
    19. return err.Error()
    20. }
    21. fillID := *f.Styles.CellXfs.Xf[styleID].FillID
    22. fgColor := f.Styles.Fills.Fill[fillID].PatternFill.FgColor
    23. if fgColor != nil {
    24. if fgColor.Theme != nil {
    25. dklt := map[int]string{
    26. 0: children[1].SysClr.LastClr,
    27. 1: children[0].SysClr.LastClr,
    28. 2: *children[3].SrgbClr.Val,
    29. 3: *children[2].SrgbClr.Val,
    30. }
    31. return strings.TrimPrefix(
    32. excelize.ThemeColor(dklt[*fgColor.Theme], fgColor.Tint), "FF")
    33. }
    34. srgbClr := *children[*fgColor.Theme].SrgbClr.Val
    35. return strings.TrimPrefix(excelize.ThemeColor(srgbClr, fgColor.Tint), "FF")
    36. }
    37. return strings.TrimPrefix(fgColor.RGB, "FF")
    38. }