Skip to content

Commit

Permalink
Merge branch 'beta-fix-styles'
Browse files Browse the repository at this point in the history
  • Loading branch information
tealeg committed Sep 13, 2024
2 parents ef66114 + 289650d commit 9590cda
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
21 changes: 16 additions & 5 deletions lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,22 +810,33 @@ func readSheetsFromZipFile(f *zip.File, file *File, sheetXMLMap map[string]strin
}()
}

var sb strings.Builder
errFound := false
err = nil
for j := 0; j < sheetCount; j++ {
sheet := <-sheetChan
if sheet == nil {
// FIXME channel leak
return wrap(fmt.Errorf("No sheet returnded from readSheetFromFile"))
errFound = true
sb.WriteString("{SheetIndex: ")
sb.WriteString(strconv.Itoa(j))
sb.WriteString("} No sheet returned from readSheetFromFile\n")
}
if sheet.Error != nil {
// FIXME channel leak
return wrap(sheet.Error)
errFound = true
sb.WriteString("{SheetIndex: ")
sb.WriteString(strconv.Itoa(sheet.Index))
sb.WriteString("} ")
sb.WriteString(sheet.Error.Error())
}
sheetName := sheet.Sheet.Name
sheetsByName[sheetName] = sheet.Sheet
sheets[sheet.Index] = sheet.Sheet
}
close(sheetChan)
return sheetsByName, sheets, nil
if errFound {
err = fmt.Errorf(sb.String())
}
return sheetsByName, sheets, err
}

// readSharedStringsFromZipFile() is an internal helper function to
Expand Down
4 changes: 2 additions & 2 deletions style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ func TestReadCellColorBackground(t *testing.T) {
cell, err = sheet.Cell(1, 1)
c.Assert(err, qt.Equals, nil)
style = cell.GetStyle()
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "00CC99FF", "00333333"))
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "00FFCC99", ""))
cell, err = sheet.Cell(2, 1)
c.Assert(err, qt.Equals, nil)
style = cell.GetStyle()
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "FF990099", "00333333"))
c.Assert(style.Fill, qt.Equals, *NewFill("solid", "FF990099", ""))
})
}

Expand Down
33 changes: 20 additions & 13 deletions xmlStyle.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,15 @@ func (styles *xlsxStyleSheet) populateStyleFromXf(style *Style, xf xlsxXf) {
style.ApplyAlignment = xf.ApplyAlignment

if xf.BorderId > -1 && xf.BorderId < styles.Borders.Count {
var border xlsxBorder
border = styles.Borders.Border[xf.BorderId]
border := styles.Borders.Border[xf.BorderId]
style.Border.Left = border.Left.Style
style.Border.LeftColor = border.Left.Color.RGB
style.Border.LeftColor = styles.argbValue(border.Left.Color)
style.Border.Right = border.Right.Style
style.Border.RightColor = border.Right.Color.RGB
style.Border.RightColor = styles.argbValue(border.Right.Color)
style.Border.Top = border.Top.Style
style.Border.TopColor = border.Top.Color.RGB
style.Border.TopColor = styles.argbValue(border.Top.Color)
style.Border.Bottom = border.Bottom.Style
style.Border.BottomColor = border.Bottom.Color.RGB
style.Border.BottomColor = styles.argbValue(border.Bottom.Color)
}

if xf.FillId > -1 && xf.FillId < styles.Fills.Count {
Expand Down Expand Up @@ -1150,13 +1149,21 @@ type xlsxColors struct {
MruColors []xlsxColor `xml:"mruColors>color,omitempty"`
}

// indexerdColor returns ARGB color string for the given index of the IndexedColors.
// Indexes start from 0, see section 18.8.27 of ECMA-376 (part 1, 4th edition).
func (c *xlsxColors) indexedColor(index int) string {
if c.IndexedColors != nil {
return c.IndexedColors[index-1].Rgb
} else {
if index < 1 || index > 64 {
return ""
}
return xlsxIndexedColors[index-1]
if index < 0 {
return ""
}

if c.IndexedColors != nil && index < len(c.IndexedColors) {
return c.IndexedColors[index].Rgb
}

// This is a weird fallback? Why would we be using indexed colours
// in a file that hasn't defined any?
if index < len(xlsxIndexedColors) {
return xlsxIndexedColors[index]
}
return ""
}
4 changes: 2 additions & 2 deletions xmlStyle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ func TestIndexedColor(t *testing.T) {

colors := xlsxColors{}
c.Run("Unitialised", func(c *qt.C) {
c.Assert(colors.indexedColor(1), qt.Equals, "FF000000")
c.Assert(colors.indexedColor(0), qt.Equals, "FF000000")
})

c.Run("Initialised", func(c *qt.C) {
colors.IndexedColors = []xlsxRgbColor{{Rgb: "00FF00FF"}}
c.Assert(colors.indexedColor(1), qt.Equals, "00FF00FF")
c.Assert(colors.indexedColor(0), qt.Equals, "00FF00FF")
})
}

Expand Down

0 comments on commit 9590cda

Please sign in to comment.