@@ -1369,14 +1369,11 @@ var (
1369
1369
}
1370
1370
)
1371
1371
1372
- // getThemeColor provides a function to convert theme color or index color to
1373
- // RGB color.
1374
- func (f * File ) getThemeColor (clr * xlsxColor ) string {
1375
- var RGB string
1376
- if clr == nil || f .Theme == nil {
1377
- return RGB
1378
- }
1379
- if clrScheme := f .Theme .ThemeElements .ClrScheme ; clr .Theme != nil {
1372
+ // GetBaseColor returns the preferred hex color code by giving hex color code,
1373
+ // indexed color, and theme color.
1374
+ func (f * File ) GetBaseColor (hexColor string , indexedColor int , themeColor * int ) string {
1375
+ if f .Theme != nil && themeColor != nil {
1376
+ clrScheme := f .Theme .ThemeElements .ClrScheme
1380
1377
if val , ok := map [int ]* string {
1381
1378
0 : & clrScheme .Lt1 .SysClr .LastClr ,
1382
1379
1 : & clrScheme .Dk1 .SysClr .LastClr ,
@@ -1388,21 +1385,35 @@ func (f *File) getThemeColor(clr *xlsxColor) string {
1388
1385
7 : clrScheme .Accent4 .SrgbClr .Val ,
1389
1386
8 : clrScheme .Accent5 .SrgbClr .Val ,
1390
1387
9 : clrScheme .Accent6 .SrgbClr .Val ,
1391
- }[* clr . Theme ]; ok && val != nil {
1392
- return strings . TrimPrefix ( ThemeColor ( * val , clr . Tint ), "FF" )
1388
+ }[* themeColor ]; ok && val != nil {
1389
+ return * val
1393
1390
}
1394
1391
}
1395
- if len (clr .RGB ) == 6 {
1396
- return clr .RGB
1392
+ if len (hexColor ) == 6 {
1393
+ return hexColor
1394
+ }
1395
+ if len (hexColor ) == 8 {
1396
+ return strings .TrimPrefix (hexColor , "FF" )
1397
+ }
1398
+ if f .Styles != nil && f .Styles .Colors != nil && f .Styles .Colors .IndexedColors != nil &&
1399
+ indexedColor < len (f .Styles .Colors .IndexedColors .RgbColor ) {
1400
+ return strings .TrimPrefix (f .Styles .Colors .IndexedColors .RgbColor [indexedColor ].RGB , "FF" )
1397
1401
}
1398
- if len (clr . RGB ) == 8 {
1399
- return strings . TrimPrefix ( clr . RGB , "FF" )
1402
+ if indexedColor < len (IndexedColorMapping ) {
1403
+ return IndexedColorMapping [ indexedColor ]
1400
1404
}
1401
- if f .Styles .Colors != nil && f .Styles .Colors .IndexedColors != nil && clr .Indexed < len (f .Styles .Colors .IndexedColors .RgbColor ) {
1402
- return strings .TrimPrefix (ThemeColor (strings .TrimPrefix (f .Styles .Colors .IndexedColors .RgbColor [clr .Indexed ].RGB , "FF" ), clr .Tint ), "FF" )
1405
+ return hexColor
1406
+ }
1407
+
1408
+ // getThemeColor provides a function to convert theme color or index color to
1409
+ // RGB color.
1410
+ func (f * File ) getThemeColor (clr * xlsxColor ) string {
1411
+ var RGB string
1412
+ if clr == nil || f .Theme == nil {
1413
+ return RGB
1403
1414
}
1404
- if clr .Indexed < len ( IndexedColorMapping ) {
1405
- return strings .TrimPrefix (ThemeColor (IndexedColorMapping [ clr . Indexed ] , clr .Tint ), "FF" )
1415
+ if RGB = f . GetBaseColor ( clr .RGB , clr . Indexed , clr . Theme ); RGB != "" {
1416
+ RGB = strings .TrimPrefix (ThemeColor (RGB , clr .Tint ), "FF" )
1406
1417
}
1407
1418
return RGB
1408
1419
}
0 commit comments