package excel import "strconv" // RGB与HEX颜色互转 type RGB struct { Red, Green, Blue int64 } type HEX struct { Str string } func t2x(t int64) string { result := strconv.FormatInt(t, 16) if len(result) == 1 { result = "0" + result } return result } func (color RGB) Rgb2Hex() HEX { r := t2x(color.Red) g := t2x(color.Green) b := t2x(color.Blue) return HEX{r + g + b} } func (color HEX) Hex2Rgb() RGB { r, _ := strconv.ParseInt(color.Str[:2], 16, 10) g, _ := strconv.ParseInt(color.Str[2:4], 16, 18) b, _ := strconv.ParseInt(color.Str[4:], 16, 10) return RGB{r, g, b} }