From d372bb977f57b244faf635e21af458bf2e8a98ef Mon Sep 17 00:00:00 2001 From: Ri Xu Date: Tue, 30 May 2017 12:13:13 +0800 Subject: [PATCH] Priority cell style, when the cell and the column at the same time with the style attribute. Relate issue #54 and #56. --- excelize.go | 15 +++++++-------- test/Workbook1.xlsx | Bin 22954 -> 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 909887af20296dd73d1d3030f2b929cf8c8784e7..8e7c88ac1696a75407cad55a88358839b6639464 100644 GIT binary patch delta 1446 zcmZ3rnQ_Nv#tm#t%#{iIHghtWGJ+Y7%pS}j#^fG0Ik3Q5HeayJ&yQSJlW^;L!j`;+_mTYzAw7$w_N_Z zV3PrNi(26I`umd^PO-h+anHlBaH( z^X<+~P*qtO9JFcHu@@e!RS|W6Hdq+^Q!4UW%F4C1BTz5Zczf=|CtH+~4oO8F_B&Qz z;i}^E^O_j%a+Rx|p_#k;jJIkBU0D%2<8!o0#57UP*v%>77o)Z*&6(!HwEsl6+n21+ zqV5>iAE(#-oU&mRW2bMR*rye)6GK%$KhHgDadS$+yYM%Yms}51^zvzr;j& zchJ9tcKt0ko(Y95H2L-C^OqgVlp41)7zpQ1-VpS{U;8HK$yIS2k?f{Hg^VK8_8dFW zoE~_1^XcsH`onpqA-?4yrR53#_jk>WyOQemYsZ8O@_D{0k$M)^5i!p@+g9WqEtZe` zW%KaqXBLi{&~uBuF0I_4m{7X^2zT}Rm|Y#`Yg_K>uDQipKHKh-=mxPGYoCWO4C2yqP z9Bi;X5PoC1^Ed75UhgestE<|cmppj+@WH0^AAIKvp1hQp_V9qv?uV(TZ(8f5uYK@g z#=3<`D~LiEJ&Sd+qL0|* zOlH2xkG(g8mCp3hQ$Otb8f+en&UX9v{d4psMuh#~d_DP{j|pFe#S5@n2tC=rw+U>_ z#!%_W7ks7o_8AbMf6#+UzKcW*B7TLvj(WP{Ar3!7en zjeyZ0RoGlp9b_xwZvs&Zqv0k#2=agw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