@@ -225,19 +225,24 @@ func xlsxAccountMonths(xlsx *excelize.File, sheet string, row int, id int, descr
225225 col := 'C'
226226 for ! t .After (ends ) {
227227 if v := bal .months [t .Format ("2006-01" )]; len (v ) == 1 {
228- _ = xlsx .SetCellValue (sheet , cell (col , row ), v [0 ].Float64 ())
228+ _ = xlsx .SetCellValue (sheet , cell (col , row ), v [0 ].amount . Float64 ())
229229 } else if len (v ) != 0 {
230230 _ = xlsx .SetCellFormula (sheet , cell (col , row ), sumFormula (v ))
231231 }
232+ if style := cellStyle (bal .months [t .Format ("2006-01" )]); style != nil {
233+ style , _ := xlsx .NewStyle (mergeStyles (defaultStyle (), customNumberFormat (), style ))
234+ _ = xlsx .SetCellStyle (sheet , cell (col , row ), cell (col , row ), style )
235+ } else {
236+ style , _ := xlsx .NewStyle (mergeStyles (defaultStyle (), customNumberFormat ()))
237+ _ = xlsx .SetCellStyle (sheet , cell (col , row ), cell (col , row ), style )
238+ }
232239 col ++
233240 t = t .AddDate (0 , 1 , 0 )
234241 }
235242 col ++
236243
237244 _ = xlsx .SetCellFormula (sheet , cell (col , row ), fmt .Sprintf ("SUM(C%d:%c%d)" , row , col - 1 , row ))
238- style , _ := xlsx .NewStyle (mergeStyles (defaultStyle (), customNumberFormat ()))
239- _ = xlsx .SetCellStyle (sheet , cell ('C' , row ), cell (col , row ), style )
240- style , _ = xlsx .NewStyle (mergeStyles (defaultStyle (), fontItalic (), customNumberFormat ()))
245+ style , _ := xlsx .NewStyle (mergeStyles (defaultStyle (), fontItalic (), customNumberFormat ()))
241246 _ = xlsx .SetCellStyle (sheet , cell (col , row ), cell (col , row ), style )
242247}
243248
@@ -324,6 +329,16 @@ func thickBorder(where ...string) *excelize.Style {
324329 return s
325330}
326331
332+ func highlight () * excelize.Style {
333+ return & excelize.Style {
334+ Fill : excelize.Fill {
335+ Type : "pattern" ,
336+ Color : []string {"#FFFF50" },
337+ Pattern : 1 ,
338+ },
339+ }
340+ }
341+
327342func mergeStyles (ext ... * excelize.Style ) * excelize.Style {
328343 if len (ext ) == 0 {
329344 return nil
@@ -462,17 +477,33 @@ func xlsxSectionSum(xlsx *excelize.File, sheet string, row int, hdr string, star
462477 _ = xlsx .SetRowHeight (sheet , row , 20 )
463478}
464479
465- func sumFormula (v []sie. Decimal ) string {
480+ func sumFormula (v []cellValue ) string {
466481 var b strings.Builder
467482 for i , d := range v {
468483 switch {
469- case i > 0 && d >= 0 :
484+ case i > 0 && d . amount >= 0 :
470485 b .WriteString (" + " )
471- case i > 0 && d < 0 :
486+ case i > 0 && d . amount < 0 :
472487 b .WriteString (" - " )
473- d = - d
488+ d . amount = - d . amount
474489 }
475- fmt .Fprintf (& b , "%v" , d .Float64 ())
490+ fmt .Fprintf (& b , "%v" , d .amount . Float64 ())
476491 }
477492 return b .String ()
478493}
494+
495+ func cellStyle (v []cellValue ) * excelize.Style {
496+ if len (v ) == 0 {
497+ return nil
498+ }
499+ var latest time.Time
500+ for _ , d := range v {
501+ if d .when .After (latest ) {
502+ latest = d .when
503+ }
504+ }
505+ if latest .After (time .Now ().AddDate (0 , 0 , - 7 )) {
506+ return highlight ()
507+ }
508+ return nil
509+ }
0 commit comments