Skip to content

Commit d372bb9

Browse files
committed
Priority cell style, when the cell and the column at the same time with the style attribute. Relate issue qax-os#54 and qax-os#56.
1 parent e41ee8a commit d372bb9

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

excelize.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,23 +135,22 @@ func (f *File) SetCellInt(sheet, axis string, value int) {
135135
completeRow(xlsx, rows, cell)
136136
completeCol(xlsx, rows, cell)
137137

138-
xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
138+
xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
139139
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
140140
xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
141141
}
142142

143143
// prepareCellStyle provides function to prepare style index of cell in
144144
// worksheet by given column index.
145-
func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col int) int {
146-
s := 0
147-
if xlsx.Cols != nil {
145+
func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
146+
if xlsx.Cols != nil && style == 0 {
148147
for _, v := range xlsx.Cols.Col {
149148
if v.Min <= col && col <= v.Max {
150-
s = v.Style
149+
style = v.Style
151150
}
152151
}
153152
}
154-
return s
153+
return style
155154
}
156155

157156
// SetCellStr provides function to set string type value of a cell. Total number
@@ -183,7 +182,7 @@ func (f *File) SetCellStr(sheet, axis, value string) {
183182
}
184183
}
185184
}
186-
xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
185+
xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
187186
xlsx.SheetData.Row[xAxis].C[yAxis].T = "str"
188187
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
189188
}
@@ -205,7 +204,7 @@ func (f *File) SetCellDefault(sheet, axis, value string) {
205204
completeRow(xlsx, rows, cell)
206205
completeCol(xlsx, rows, cell)
207206

208-
xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
207+
xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
209208
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
210209
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
211210
}

test/Workbook1.xlsx

14 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)