@@ -237,16 +237,15 @@ func (styles *xlsxStyleSheet) populateStyleFromXf(style *Style, xf xlsxXf) {
237237 style .ApplyAlignment = xf .ApplyAlignment
238238
239239 if xf .BorderId > - 1 && xf .BorderId < styles .Borders .Count {
240- var border xlsxBorder
241- border = styles .Borders .Border [xf .BorderId ]
240+ border := styles .Borders .Border [xf .BorderId ]
242241 style .Border .Left = border .Left .Style
243- style .Border .LeftColor = border .Left .Color . RGB
242+ style .Border .LeftColor = styles . argbValue ( border .Left .Color )
244243 style .Border .Right = border .Right .Style
245- style .Border .RightColor = border .Right .Color . RGB
244+ style .Border .RightColor = styles . argbValue ( border .Right .Color )
246245 style .Border .Top = border .Top .Style
247- style .Border .TopColor = border .Top .Color . RGB
246+ style .Border .TopColor = styles . argbValue ( border .Top .Color )
248247 style .Border .Bottom = border .Bottom .Style
249- style .Border .BottomColor = border .Bottom .Color . RGB
248+ style .Border .BottomColor = styles . argbValue ( border .Bottom .Color )
250249 }
251250
252251 if xf .FillId > - 1 && xf .FillId < styles .Fills .Count {
@@ -1150,13 +1149,21 @@ type xlsxColors struct {
11501149 MruColors []xlsxColor `xml:"mruColors>color,omitempty"`
11511150}
11521151
1152+ // indexerdColor returns ARGB color string for the given index of the IndexedColors.
1153+ // Indexes start from 0, see section 18.8.27 of ECMA-376 (part 1, 4th edition).
11531154func (c * xlsxColors ) indexedColor (index int ) string {
1154- if c .IndexedColors != nil {
1155- return c .IndexedColors [index - 1 ].Rgb
1156- } else {
1157- if index < 1 || index > 64 {
1158- return ""
1159- }
1160- return xlsxIndexedColors [index - 1 ]
1155+ if index < 0 {
1156+ return ""
1157+ }
1158+
1159+ if c .IndexedColors != nil && index < len (c .IndexedColors ) {
1160+ return c .IndexedColors [index ].Rgb
1161+ }
1162+
1163+ // This is a weird fallback? Why would we be using indexed colours
1164+ // in a file that hasn't defined any?
1165+ if index < len (xlsxIndexedColors ) {
1166+ return xlsxIndexedColors [index ]
11611167 }
1168+ return ""
11621169}
0 commit comments