@ -289,7 +289,12 @@ func TestSetCellStyleAlignment(t *testing.T) {
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet1" , "A22" , "A22" , ` { "alignment": { "horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"top","wrap_text":true}} ` )
var style int
style , err = xlsx . NewStyle ( ` { "alignment": { "horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"top","wrap_text":true}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "A22" , "A22" , style )
err = xlsx . Save ( )
if err != nil {
t . Log ( err )
@ -301,30 +306,47 @@ func TestSetCellStyleBorder(t *testing.T) {
if err != nil {
t . Log ( err )
}
var style int
// Test set border with invalid style parameter.
err = xlsx . SetCellStyle ( "Sheet1" , "J21" , "L25" , "" )
style, err = xlsx . NewStyle ( "" )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "J21" , "L25" , style )
// Test set border with invalid style index number.
err = xlsx . SetCellStyle ( "Sheet1" , "J21" , "L25" , ` { "border":[ { "type":"left","color":"0000FF","style":-1}, { "type":"top","color":"00FF00","style":14}, { "type":"bottom","color":"FFFF00","style":5}, { "type":"right","color":"FF0000","style":6}, { "type":"diagonalDown","color":"A020F0","style":9}, { "type":"diagonalUp","color":"A020F0","style":8}]} ` )
style, err = xlsx . NewStyle ( ` { "border":[ { "type":"left","color":"0000FF","style":-1}, { "type":"top","color":"00FF00","style":14}, { "type":"bottom","color":"FFFF00","style":5}, { "type":"right","color":"FF0000","style":6}, { "type":"diagonalDown","color":"A020F0","style":9}, { "type":"diagonalUp","color":"A020F0","style":8}]} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "J21" , "L25" , style )
// Test set border on overlapping area with vertical variants shading styles gradient fill.
err = xlsx . SetCellStyle ( "Sheet1" , "J21" , "L25" , ` { "border":[ { "type":"left","color":"0000FF","style":2}, { "type":"top","color":"00FF00","style":12}, { "type":"bottom","color":"FFFF00","style":5}, { "type":"right","color":"FF0000","style":6}, { "type":"diagonalDown","color":"A020F0","style":9}, { "type":"diagonalUp","color":"A020F0","style":8}]} ` )
style, err = xlsx . NewStyle ( ` { "border":[ { "type":"left","color":"0000FF","style":2}, { "type":"top","color":"00FF00","style":12}, { "type":"bottom","color":"FFFF00","style":5}, { "type":"right","color":"FF0000","style":6}, { "type":"diagonalDown","color":"A020F0","style":9}, { "type":"diagonalUp","color":"A020F0","style":8}]} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet1" , "M28" , "K24" , ` { "border":[ { "type":"left","color":"0000FF","style":2}, { "type":"top","color":"00FF00","style":3}, { "type":"bottom","color":"FFFF00","style":4}, { "type":"right","color":"FF0000","style":5}, { "type":"diagonalDown","color":"A020F0","style":6}, { "type":"diagonalUp","color":"A020F0","style":7}],"fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}} ` )
xlsx . SetCellStyle ( "Sheet1" , "J21" , "L25" , style )
style , err = xlsx . NewStyle ( ` { "border":[ { "type":"left","color":"0000FF","style":2}, { "type":"top","color":"00FF00","style":3}, { "type":"bottom","color":"FFFF00","style":4}, { "type":"right","color":"FF0000","style":5}, { "type":"diagonalDown","color":"A020F0","style":6}, { "type":"diagonalUp","color":"A020F0","style":7}],"fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "M28" , "K24" , style )
style , err = xlsx . NewStyle ( ` { "border":[ { "type":"left","color":"0000FF","style":2}, { "type":"top","color":"00FF00","style":3}, { "type":"bottom","color":"FFFF00","style":4}, { "type":"right","color":"FF0000","style":5}, { "type":"diagonalDown","color":"A020F0","style":6}, { "type":"diagonalUp","color":"A020F0","style":7}],"fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":4}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "M28" , "K24" , style )
// Test set border and solid style pattern fill for a single cell.
err = xlsx . SetCellStyle ( "Sheet1" , "O22" , "O22" , ` { "border":[ { "type":"left","color":"0000FF","style":8}, { "type":"top","color":"00FF00","style":9}, { "type":"bottom","color":"FFFF00","style":10}, { "type":"right","color":"FF0000","style":11}, { "type":"diagonalDown","color":"A020F0","style":12}, { "type":"diagonalUp","color":"A020F0","style":13}],"fill": { "type":"pattern","color":["#E0EBF5"],"pattern":1}} ` )
style, err = xlsx . NewStyle ( ` { "border":[ { "type":"left","color":"0000FF","style":8}, { "type":"top","color":"00FF00","style":9}, { "type":"bottom","color":"FFFF00","style":10}, { "type":"right","color":"FF0000","style":11}, { "type":"diagonalDown","color":"A020F0","style":12}, { "type":"diagonalUp","color":"A020F0","style":13}],"fill": { "type":"pattern","color":["#E0EBF5"],"pattern":1}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "O22" , "O22" , style )
err = xlsx . Save ( )
if err != nil {
t . Log ( err )
@ -350,13 +372,20 @@ func TestSetCellStyleNumberFormat(t *testing.T) {
} else {
xlsx . SetCellValue ( "Sheet2" , c , val )
}
err := xlsx . SetCellStyle ( "Sheet2" , c , c , ` { "fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":5},"number_format": ` + strconv . Itoa ( d ) + ` } ` )
style, err := xlsx . NewStyle ( ` { "fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":5},"number_format": ` + strconv . Itoa ( d ) + ` } ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet2" , c , c , style )
t . Log ( xlsx . GetCellValue ( "Sheet2" , c ) )
}
}
var style int
style , err = xlsx . NewStyle ( ` { "number_format":-1} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet2" , "L33" , "L33" , style )
err = xlsx . Save ( )
if err != nil {
t . Log ( err )
@ -368,24 +397,32 @@ func TestSetCellStyleFill(t *testing.T) {
if err != nil {
t . Log ( err )
}
var style int
// Test set fill for cell with invalid parameter.
err = xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , ` { "fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":6}} ` )
style, err = xlsx . NewStyle ( ` { "fill": { "type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":6}} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , ` { "fill": { "type":"gradient","color":["#FFFFFF"],"shading":1}} ` )
xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , style )
style , err = xlsx . NewStyle ( ` { "fill": { "type":"gradient","color":["#FFFFFF"],"shading":1}} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , ` { "fill": { "type":"pattern","color":[],"pattern":1}} ` )
xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , style )
style , err = xlsx . NewStyle ( ` { "fill": { "type":"pattern","color":[],"pattern":1}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , style )
err = xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , ` { "fill": { "type":"pattern","color":["#E0EBF5"],"pattern":19}} ` )
style, err = xlsx . NewStyle ( ` { "fill": { "type":"pattern","color":["#E0EBF5"],"pattern":19}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet1" , "O23" , "O23" , style )
err = xlsx . Save ( )
if err != nil {
t . Log ( err )
@ -397,26 +434,36 @@ func TestSetCellStyleFont(t *testing.T) {
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet2" , "A1" , "A1" , ` { "font": { "bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}} ` )
var style int
style , err = xlsx . NewStyle ( ` { "font": { "bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777","underline":"single"}} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet2" , "A2" , "A2" , ` { "font": { "italic":true,"underline":"double"}} ` )
xlsx . SetCellStyle ( "Sheet2" , "A1" , "A1" , style )
style , err = xlsx . NewStyle ( ` { "font": { "italic":true,"underline":"double"}} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet2" , "A3" , "A3" , ` { "font": { "bold":true}} ` )
xlsx . SetCellStyle ( "Sheet2" , "A2" , "A2" , style )
style , err = xlsx . NewStyle ( ` { "font": { "bold":true}} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet2" , "A4" , "A4" , ` { "font": { "bold":true,"family":"","size":0,"color":"","underline":""}} ` )
xlsx . SetCellStyle ( "Sheet2" , "A3" , "A3" , style )
style , err = xlsx . NewStyle ( ` { "font": { "bold":true,"family":"","size":0,"color":"","underline":""}} ` )
if err != nil {
t . Log ( err )
}
err = xlsx . SetCellStyle ( "Sheet2" , "A5" , "A5" , ` { "font": { "color":"#777777"}} ` )
xlsx . SetCellStyle ( "Sheet2" , "A4" , "A4" , style )
style , err = xlsx . NewStyle ( ` { "font": { "color":"#777777"}} ` )
if err != nil {
t . Log ( err )
}
xlsx . SetCellStyle ( "Sheet2" , "A5" , "A5" , style )
err = xlsx . Save ( )
if err != nil {
t . Log ( err )