This closed #1163, fix set cell value with column and row style inherit issue
This commit is contained in:
parent
c2311ce87d
commit
19a0cf3cec
10
cell.go
10
cell.go
|
@ -1145,6 +1145,11 @@ func (f *File) prepareCellStyle(ws *xlsxWorksheet, col, row, style int) int {
|
|||
if style != 0 {
|
||||
return style
|
||||
}
|
||||
if row <= len(ws.SheetData.Row) {
|
||||
if styleID := ws.SheetData.Row[row-1].S; styleID != 0 {
|
||||
return styleID
|
||||
}
|
||||
}
|
||||
if ws.Cols != nil {
|
||||
for _, c := range ws.Cols.Col {
|
||||
if c.Min <= col && col <= c.Max && c.Style != 0 {
|
||||
|
@ -1152,11 +1157,6 @@ func (f *File) prepareCellStyle(ws *xlsxWorksheet, col, row, style int) int {
|
|||
}
|
||||
}
|
||||
}
|
||||
if row <= len(ws.SheetData.Row) {
|
||||
if styleID := ws.SheetData.Row[row-1].S; styleID != 0 {
|
||||
return styleID
|
||||
}
|
||||
}
|
||||
return style
|
||||
}
|
||||
|
||||
|
|
15
cell_test.go
15
cell_test.go
|
@ -156,6 +156,21 @@ func TestSetCellValue(t *testing.T) {
|
|||
f := NewFile()
|
||||
assert.EqualError(t, f.SetCellValue("Sheet1", "A", time.Now().UTC()), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
|
||||
assert.EqualError(t, f.SetCellValue("Sheet1", "A", time.Duration(1e13)), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")).Error())
|
||||
// Test set cell value with column and row style inherit
|
||||
style1, err := f.NewStyle(&Style{NumFmt: 2})
|
||||
assert.NoError(t, err)
|
||||
style2, err := f.NewStyle(&Style{NumFmt: 9})
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, f.SetColStyle("Sheet1", "B", style1))
|
||||
assert.NoError(t, f.SetRowStyle("Sheet1", 1, 1, style2))
|
||||
assert.NoError(t, f.SetCellValue("Sheet1", "B1", 0.5))
|
||||
assert.NoError(t, f.SetCellValue("Sheet1", "B2", 0.5))
|
||||
B1, err := f.GetCellValue("Sheet1", "B1")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "50%", B1)
|
||||
B2, err := f.GetCellValue("Sheet1", "B2")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "0.50", B2)
|
||||
}
|
||||
|
||||
func TestSetCellValues(t *testing.T) {
|
||||
|
|
|
@ -901,7 +901,7 @@ func formatToC(v, format string, date1904 bool) string {
|
|||
if err != nil {
|
||||
return v
|
||||
}
|
||||
f = f * 100
|
||||
f *= 100
|
||||
return fmt.Sprintf("%.f%%", f)
|
||||
}
|
||||
|
||||
|
@ -912,7 +912,7 @@ func formatToD(v, format string, date1904 bool) string {
|
|||
if err != nil {
|
||||
return v
|
||||
}
|
||||
f = f * 100
|
||||
f *= 100
|
||||
return fmt.Sprintf("%.2f%%", f)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue