Skip to content

Commit 0c7c714

Browse files
committed
Resolve qax-os#470, export Style structs to allow create the style for cells by given JSON or structure
1 parent 69319bd commit 0c7c714

File tree

8 files changed

+207
-126
lines changed

8 files changed

+207
-126
lines changed

excelize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (f *File) setDefaultTimeStyle(sheet, axis string, format int) error {
137137
return err
138138
}
139139
if s == 0 {
140-
style, _ := f.NewStyle(`{"number_format": ` + strconv.Itoa(format) + `}`)
140+
style, _ := f.NewStyle(&Style{NumFmt: format})
141141
_ = f.SetCellStyle(sheet, axis, axis, style)
142142
}
143143
return err

excelize_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,45 @@ func TestSetCellStyleBorder(t *testing.T) {
580580
assert.NoError(t, f.SetCellStyle("Sheet1", "M28", "K24", style))
581581

582582
// Test set border and solid style pattern fill for a single cell.
583-
style, err = f.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}}`)
583+
style, err = f.NewStyle(&Style{
584+
Border: []Border{
585+
{
586+
Type: "left",
587+
Color: "0000FF",
588+
Style: 8,
589+
},
590+
{
591+
Type: "top",
592+
Color: "00FF00",
593+
Style: 9,
594+
},
595+
{
596+
Type: "bottom",
597+
Color: "FFFF00",
598+
Style: 10,
599+
},
600+
{
601+
Type: "right",
602+
Color: "FF0000",
603+
Style: 11,
604+
},
605+
{
606+
Type: "diagonalDown",
607+
Color: "A020F0",
608+
Style: 12,
609+
},
610+
{
611+
Type: "diagonalUp",
612+
Color: "A020F0",
613+
Style: 13,
614+
},
615+
},
616+
Fill: Fill{
617+
Type: "pattern",
618+
Color: []string{"#E0EBF5"},
619+
Pattern: 1,
620+
},
621+
})
584622
if !assert.NoError(t, err) {
585623
t.FailNow()
586624
}

shape.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ func (f *File) addDrawingShape(sheet, drawingXML, cell string, formatSet *format
378378
if len(formatSet.Paragraph) < 1 {
379379
formatSet.Paragraph = []formatShapeParagraph{
380380
{
381-
Font: formatFont{
381+
Font: Font{
382382
Bold: false,
383383
Italic: false,
384384
Underline: "none",

0 commit comments

Comments
 (0)