summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRi Xu <xuri.me@gmail.com>2017-05-30 12:13:13 +0800
committerRi Xu <xuri.me@gmail.com>2017-05-30 12:13:13 +0800
commitd372bb977f57b244faf635e21af458bf2e8a98ef (patch)
tree59989b20d89b3401ca74e5ed71b8b5d710a39d01
parente41ee8a12437250034620285c926cdecbff85e00 (diff)
Priority cell style, when the cell and the column at the same time with the style attribute. Relate issue #54 and #56.
-rw-r--r--excelize.go15
-rw-r--r--test/Workbook1.xlsxbin22954 -> 22968 bytes
2 files changed, 7 insertions, 8 deletions
diff --git a/excelize.go b/excelize.go
index cd5e86e..fa9c004 100644
--- a/excelize.go
+++ b/excelize.go
@@ -135,23 +135,22 @@ func (f *File) SetCellInt(sheet, axis string, value int) {
completeRow(xlsx, rows, cell)
completeCol(xlsx, rows, cell)
- xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
+ xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
xlsx.SheetData.Row[xAxis].C[yAxis].V = strconv.Itoa(value)
}
// prepareCellStyle provides function to prepare style index of cell in
// worksheet by given column index.
-func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col int) int {
- s := 0
- if xlsx.Cols != nil {
+func (f *File) prepareCellStyle(xlsx *xlsxWorksheet, col, style int) int {
+ if xlsx.Cols != nil && style == 0 {
for _, v := range xlsx.Cols.Col {
if v.Min <= col && col <= v.Max {
- s = v.Style
+ style = v.Style
}
}
}
- return s
+ return style
}
// 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) {
}
}
}
- xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
+ xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
xlsx.SheetData.Row[xAxis].C[yAxis].T = "str"
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
}
@@ -205,7 +204,7 @@ func (f *File) SetCellDefault(sheet, axis, value string) {
completeRow(xlsx, rows, cell)
completeCol(xlsx, rows, cell)
- xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell)
+ xlsx.SheetData.Row[xAxis].C[yAxis].S = f.prepareCellStyle(xlsx, cell, xlsx.SheetData.Row[xAxis].C[yAxis].S)
xlsx.SheetData.Row[xAxis].C[yAxis].T = ""
xlsx.SheetData.Row[xAxis].C[yAxis].V = value
}
diff --git a/test/Workbook1.xlsx b/test/Workbook1.xlsx
index 909887a..8e7c88a 100644
--- a/test/Workbook1.xlsx
+++ b/test/Workbook1.xlsx
Binary files differ