Skip to content

Commit 9590cda

Browse files
committed
Merge branch 'beta-fix-styles'
2 parents ef66114 + 289650d commit 9590cda

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

lib.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -810,22 +810,33 @@ func readSheetsFromZipFile(f *zip.File, file *File, sheetXMLMap map[string]strin
810810
}()
811811
}
812812

813+
var sb strings.Builder
814+
errFound := false
815+
err = nil
813816
for j := 0; j < sheetCount; j++ {
814817
sheet := <-sheetChan
815818
if sheet == nil {
816-
// FIXME channel leak
817-
return wrap(fmt.Errorf("No sheet returnded from readSheetFromFile"))
819+
errFound = true
820+
sb.WriteString("{SheetIndex: ")
821+
sb.WriteString(strconv.Itoa(j))
822+
sb.WriteString("} No sheet returned from readSheetFromFile\n")
818823
}
819824
if sheet.Error != nil {
820-
// FIXME channel leak
821-
return wrap(sheet.Error)
825+
errFound = true
826+
sb.WriteString("{SheetIndex: ")
827+
sb.WriteString(strconv.Itoa(sheet.Index))
828+
sb.WriteString("} ")
829+
sb.WriteString(sheet.Error.Error())
822830
}
823831
sheetName := sheet.Sheet.Name
824832
sheetsByName[sheetName] = sheet.Sheet
825833
sheets[sheet.Index] = sheet.Sheet
826834
}
827835
close(sheetChan)
828-
return sheetsByName, sheets, nil
836+
if errFound {
837+
err = fmt.Errorf(sb.String())
838+
}
839+
return sheetsByName, sheets, err
829840
}
830841

831842
// readSharedStringsFromZipFile() is an internal helper function to

style_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ func TestReadCellColorBackground(t *testing.T) {
7474
cell, err = sheet.Cell(1, 1)
7575
c.Assert(err, qt.Equals, nil)
7676
style = cell.GetStyle()
77-
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "00CC99FF", "00333333"))
77+
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "00FFCC99", ""))
7878
cell, err = sheet.Cell(2, 1)
7979
c.Assert(err, qt.Equals, nil)
8080
style = cell.GetStyle()
81-
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "FF990099", "00333333"))
81+
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "FF990099", ""))
8282
})
8383
}
8484

xmlStyle.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -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).
11531154
func (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
}

xmlStyle_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ func TestIndexedColor(t *testing.T) {
1212

1313
colors := xlsxColors{}
1414
c.Run("Unitialised", func(c *qt.C) {
15-
c.Assert(colors.indexedColor(1), qt.Equals, "FF000000")
15+
c.Assert(colors.indexedColor(0), qt.Equals, "FF000000")
1616
})
1717

1818
c.Run("Initialised", func(c *qt.C) {
1919
colors.IndexedColors = []xlsxRgbColor{{Rgb: "00FF00FF"}}
20-
c.Assert(colors.indexedColor(1), qt.Equals, "00FF00FF")
20+
c.Assert(colors.indexedColor(0), qt.Equals, "00FF00FF")
2121
})
2222
}
2323

0 commit comments

Comments
 (0)