From f91f548614a7182ce66d55d10ed311e9b7e08a2a Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 17 May 2019 22:58:12 +0800 Subject: Resolve #404, get sheet map by target rels. --- styles.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index d6d267d..fc8a290 100644 --- a/styles.go +++ b/styles.go @@ -1895,11 +1895,8 @@ func (f *File) NewStyle(style string) (int, error) { numFmtID := setNumFmt(s, fs) if fs.Font != nil { - font, _ := xml.Marshal(setFont(fs)) s.Fonts.Count++ - s.Fonts.Font = append(s.Fonts.Font, &xlsxFont{ - Font: string(font[6 : len(font)-7]), - }) + s.Fonts.Font = append(s.Fonts.Font, setFont(fs)) fontID = s.Fonts.Count - 1 } @@ -1950,7 +1947,7 @@ func (f *File) NewConditionalStyle(style string) (int, error) { // setFont provides a function to add font style by given cell format // settings. -func setFont(formatStyle *formatStyle) *font { +func setFont(formatStyle *formatStyle) *xlsxFont { fontUnderlineType := map[string]string{"single": "single", "double": "double"} if formatStyle.Font.Size < 1 { formatStyle.Font.Size = 11 @@ -1958,7 +1955,7 @@ func setFont(formatStyle *formatStyle) *font { if formatStyle.Font.Color == "" { formatStyle.Font.Color = "#000000" } - f := font{ + f := xlsxFont{ B: formatStyle.Font.Bold, I: formatStyle.Font.Italic, Sz: &attrValInt{Val: formatStyle.Font.Size}, -- cgit v1.2.1 From b1c9884f6d186bd1bfb4fc1d34061856345b8530 Mon Sep 17 00:00:00 2001 From: Harris Date: Thu, 25 Apr 2019 11:24:25 -0500 Subject: Add the ability to change the default font Closes #390 --- styles.go | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index fc8a290..e0e6f78 100644 --- a/styles.go +++ b/styles.go @@ -1896,7 +1896,7 @@ func (f *File) NewStyle(style string) (int, error) { if fs.Font != nil { s.Fonts.Count++ - s.Fonts.Font = append(s.Fonts.Font, setFont(fs)) + s.Fonts.Font = append(s.Fonts.Font, f.setFont(fs)) fontID = s.Fonts.Count - 1 } @@ -1932,7 +1932,7 @@ func (f *File) NewConditionalStyle(style string) (int, error) { Border: setBorders(fs), } if fs.Font != nil { - dxf.Font = setFont(fs) + dxf.Font = f.setFont(fs) } dxfStr, _ := xml.Marshal(dxf) if s.Dxfs == nil { @@ -1945,9 +1945,32 @@ func (f *File) NewConditionalStyle(style string) (int, error) { return s.Dxfs.Count - 1, nil } +// GetDefaultFont provides the default font name currently set in the workbook +// Documents generated by excelize start with Calibri +func (f *File) GetDefaultFont() string { + font := f.readDefaultFont() + return font.Name.Val +} + +// SetDefaultFont changes the default font in the workbook +func (f *File) SetDefaultFont(fontName string) { + font := f.readDefaultFont() + font.Name.Val = fontName + s := f.stylesReader() + s.Fonts.Font[0] = font + custom := true + s.CellStyles.CellStyle[0].CustomBuiltIn = &custom +} + +// readDefaultFont provides an unmarshalled font value +func (f *File) readDefaultFont() *xlsxFont { + s := f.stylesReader() + return s.Fonts.Font[0] +} + // setFont provides a function to add font style by given cell format // settings. -func setFont(formatStyle *formatStyle) *xlsxFont { +func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { fontUnderlineType := map[string]string{"single": "single", "double": "double"} if formatStyle.Font.Size < 1 { formatStyle.Font.Size = 11 @@ -1955,7 +1978,7 @@ func setFont(formatStyle *formatStyle) *xlsxFont { if formatStyle.Font.Color == "" { formatStyle.Font.Color = "#000000" } - f := xlsxFont{ + fnt := xlsxFont{ B: formatStyle.Font.Bold, I: formatStyle.Font.Italic, Sz: &attrValInt{Val: formatStyle.Font.Size}, @@ -1963,15 +1986,14 @@ func setFont(formatStyle *formatStyle) *xlsxFont { Name: &attrValString{Val: formatStyle.Font.Family}, Family: &attrValInt{Val: 2}, } - if f.Name.Val == "" { - f.Name.Val = "Calibri" - f.Scheme = &attrValString{Val: "minor"} + if fnt.Name.Val == "" { + fnt.Name.Val = f.GetDefaultFont() } val, ok := fontUnderlineType[formatStyle.Font.Underline] if ok { - f.U = &attrValString{Val: val} + fnt.U = &attrValString{Val: val} } - return &f + return &fnt } // setNumFmt provides a function to check if number format code in the range -- cgit v1.2.1 From 3997dee1f58c81444733e1756da6138d4ce445f1 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 7 Jun 2019 09:16:55 +0800 Subject: Fix #411, change font size to float type --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 styles.go (limited to 'styles.go') diff --git a/styles.go b/styles.go old mode 100644 new mode 100755 index e0e6f78..1cae186 --- a/styles.go +++ b/styles.go @@ -1981,7 +1981,7 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { fnt := xlsxFont{ B: formatStyle.Font.Bold, I: formatStyle.Font.Italic, - Sz: &attrValInt{Val: formatStyle.Font.Size}, + Sz: &attrValFloat{Val: formatStyle.Font.Size}, Color: &xlsxColor{RGB: getPaletteColor(formatStyle.Font.Color)}, Name: &attrValString{Val: formatStyle.Font.Family}, Family: &attrValInt{Val: 2}, -- cgit v1.2.1 From 421f945f51f254054991127758db0520cf0f5456 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 8 Jun 2019 00:00:55 +0800 Subject: Fixed #418, #420, #421, init adjust calculation chain support Update testing case --- styles.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 1cae186..5c4f66e 100755 --- a/styles.go +++ b/styles.go @@ -1979,8 +1979,8 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { formatStyle.Font.Color = "#000000" } fnt := xlsxFont{ - B: formatStyle.Font.Bold, - I: formatStyle.Font.Italic, + B: &formatStyle.Font.Bold, + I: &formatStyle.Font.Italic, Sz: &attrValFloat{Val: formatStyle.Font.Size}, Color: &xlsxColor{RGB: getPaletteColor(formatStyle.Font.Color)}, Name: &attrValString{Val: formatStyle.Font.Family}, -- cgit v1.2.1 From 821632cf89422b9955160a3af7f28f05a12f70f8 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 12 Jun 2019 08:10:33 +0800 Subject: Fix #424, refactor merged cells adjuster --- styles.go | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 styles.go (limited to 'styles.go') diff --git a/styles.go b/styles.go old mode 100755 new mode 100644 -- cgit v1.2.1 From e124f6000a2ea731b96a07d6bf2901781e272d90 Mon Sep 17 00:00:00 2001 From: xuri Date: Thu, 13 Jun 2019 08:25:35 +0800 Subject: Fix #425, handle empty font style format --- styles.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 5c4f66e..1c01421 100644 --- a/styles.go +++ b/styles.go @@ -1979,13 +1979,17 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { formatStyle.Font.Color = "#000000" } fnt := xlsxFont{ - B: &formatStyle.Font.Bold, - I: &formatStyle.Font.Italic, Sz: &attrValFloat{Val: formatStyle.Font.Size}, Color: &xlsxColor{RGB: getPaletteColor(formatStyle.Font.Color)}, Name: &attrValString{Val: formatStyle.Font.Family}, Family: &attrValInt{Val: 2}, } + if formatStyle.Font.Bold { + fnt.B = &formatStyle.Font.Bold + } + if formatStyle.Font.Italic { + fnt.I = &formatStyle.Font.Italic + } if fnt.Name.Val == "" { fnt.Name.Val = f.GetDefaultFont() } -- cgit v1.2.1 From dc8210d4a7d18f6425f6f18dc383b26778883715 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 30 Jun 2019 19:50:47 +0800 Subject: Update GoDoc and typo fixed --- styles.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 1c01421..b246e30 100644 --- a/styles.go +++ b/styles.go @@ -1946,13 +1946,13 @@ func (f *File) NewConditionalStyle(style string) (int, error) { } // GetDefaultFont provides the default font name currently set in the workbook -// Documents generated by excelize start with Calibri +// Documents generated by excelize start with Calibri. func (f *File) GetDefaultFont() string { font := f.readDefaultFont() return font.Name.Val } -// SetDefaultFont changes the default font in the workbook +// SetDefaultFont changes the default font in the workbook. func (f *File) SetDefaultFont(fontName string) { font := f.readDefaultFont() font.Name.Val = fontName @@ -1962,7 +1962,7 @@ func (f *File) SetDefaultFont(fontName string) { s.CellStyles.CellStyle[0].CustomBuiltIn = &custom } -// readDefaultFont provides an unmarshalled font value +// readDefaultFont provides an unmarshalled font value. func (f *File) readDefaultFont() *xlsxFont { s := f.stylesReader() return s.Fonts.Font[0] -- cgit v1.2.1 From cbe919fdf6c00733513494680b89171b8b1b41a1 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 4 Aug 2019 20:24:59 +0800 Subject: New feature: sparkline supported --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index b246e30..04a5c33 100644 --- a/styles.go +++ b/styles.go @@ -1010,7 +1010,7 @@ func (f *File) stylesReader() *xlsxStyleSheet { func (f *File) styleSheetWriter() { if f.Styles != nil { output, _ := xml.Marshal(f.Styles) - f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + f.saveFileList("xl/styles.xml", replaceStyleRelationshipsNameSpaceBytes(output)) } } -- cgit v1.2.1 From 9c70d0ac868f66badf2663cc7b4b3c46d5411131 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 11 Aug 2019 00:36:14 +0800 Subject: Documentation updated, Go 1.10+ required --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 04a5c33..c19cee0 100644 --- a/styles.go +++ b/styles.go @@ -5,7 +5,7 @@ // Package excelize providing a set of functions that allow you to write to // and read from XLSX files. Support reads and writes XLSX file generated by // Microsoft Excelâ„¢ 2007 and later. Support save file without losing original -// charts of XLSX. This library needs Go version 1.8 or later. +// charts of XLSX. This library needs Go version 1.10 or later. package excelize -- cgit v1.2.1 From 407fb55c20a2524c4eccad9361120dee2a2719cd Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 21 Aug 2019 23:03:34 +0800 Subject: Update the Godoc --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index c19cee0..16f8030 100644 --- a/styles.go +++ b/styles.go @@ -2351,7 +2351,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // Set font style for cell H9 on Sheet1: // -// style, err := f.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Berlin Sans FB Demi","size":36,"color":"#777777"}}`) +// style, err := f.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Times New Roman","size":36,"color":"#777777"}}`) // if err != nil { // fmt.Println(err) // } -- cgit v1.2.1 From 1fc4bc52fb8a0160eb624e7a24619d8c0e47e540 Mon Sep 17 00:00:00 2001 From: Vsevolod Balashov Date: Sun, 1 Sep 2019 07:30:14 +0300 Subject: Fix #386 regression test added (#440) * #386 regression test added * closes #386 string to bigint on GOARCH=386 --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 16f8030..4d6071a 100644 --- a/styles.go +++ b/styles.go @@ -852,7 +852,7 @@ func formatToInt(i int, v string) string { if err != nil { return v } - return fmt.Sprintf("%d", int(f)) + return fmt.Sprintf("%d", int64(f)) } // formatToFloat provides a function to convert original string to float -- cgit v1.2.1 From 75d66a03f33f25c29167c5f75ee8a4cc58598420 Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 23 Sep 2019 21:50:03 +0800 Subject: Fix #482, font strike style support --- styles.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 4d6071a..3244be2 100644 --- a/styles.go +++ b/styles.go @@ -1993,6 +1993,10 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { if fnt.Name.Val == "" { fnt.Name.Val = f.GetDefaultFont() } + if formatStyle.Font.Strike { + strike := true + fnt.Strike = &strike + } val, ok := fontUnderlineType[formatStyle.Font.Underline] if ok { fnt.U = &attrValString{Val: val} -- cgit v1.2.1 From b1b3c0d15158abc71267da5893de020f047c3872 Mon Sep 17 00:00:00 2001 From: Alex Geer Date: Thu, 19 Dec 2019 19:30:48 +0300 Subject: =?UTF-8?q?Fix=20#539=20Fixed=20error=20opening=20excel=20file=20c?= =?UTF-8?q?reated=20in=20encoding=20d=E2=80=A6=20(#540)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed issue #539 Fixed error opening excel file created in encoding different from UTF-8, added logging of possible errors when decoding XML if the function does not provide exit with an error * Added test for CharsetReader * Fixed #discussion_r359397878 Discussion: https://github.com/360EntSecGroup-Skylar/excelize/pull/540#discussion_r359397878 * Fixed go fmt * go mod tidy and removed unused imports * The code has been refactored --- styles.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 3244be2..fa0507e 100644 --- a/styles.go +++ b/styles.go @@ -10,9 +10,12 @@ package excelize import ( + "bytes" "encoding/json" "encoding/xml" "fmt" + "io" + "log" "math" "strconv" "strings" @@ -997,11 +1000,16 @@ func is12HourTime(format string) bool { // stylesReader provides a function to get the pointer to the structure after // deserialization of xl/styles.xml. func (f *File) stylesReader() *xlsxStyleSheet { + var err error + if f.Styles == nil { - var styleSheet xlsxStyleSheet - _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/styles.xml")), &styleSheet) - f.Styles = &styleSheet + f.Styles = new(xlsxStyleSheet) + if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML("xl/styles.xml")))). + Decode(f.Styles); err != nil && err != io.EOF { + log.Printf("xml decode error: %s", err) + } } + return f.Styles } @@ -2803,8 +2811,16 @@ func getPaletteColor(color string) string { // themeReader provides a function to get the pointer to the xl/theme/theme1.xml // structure after deserialization. func (f *File) themeReader() *xlsxTheme { - var theme xlsxTheme - _ = xml.Unmarshal(namespaceStrictToTransitional(f.readXML("xl/theme/theme1.xml")), &theme) + var ( + err error + theme xlsxTheme + ) + + if err = f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(f.readXML("xl/theme/theme1.xml")))). + Decode(&theme); err != nil && err != io.EOF { + log.Printf("xml decoder error: %s", err) + } + return &theme } -- cgit v1.2.1 From 4e4a5b9b3e052d1694442515492792fb1aa74c5a Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 23 Dec 2019 00:07:40 +0800 Subject: Improve compatibility, fix workbook's rels ID calc error --- styles.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index fa0507e..56c7196 100644 --- a/styles.go +++ b/styles.go @@ -1957,13 +1957,13 @@ func (f *File) NewConditionalStyle(style string) (int, error) { // Documents generated by excelize start with Calibri. func (f *File) GetDefaultFont() string { font := f.readDefaultFont() - return font.Name.Val + return *font.Name.Val } // SetDefaultFont changes the default font in the workbook. func (f *File) SetDefaultFont(fontName string) { font := f.readDefaultFont() - font.Name.Val = fontName + font.Name.Val = stringPtr(fontName) s := f.stylesReader() s.Fonts.Font[0] = font custom := true @@ -1987,10 +1987,10 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { formatStyle.Font.Color = "#000000" } fnt := xlsxFont{ - Sz: &attrValFloat{Val: formatStyle.Font.Size}, + Sz: &attrValFloat{Val: float64Ptr(formatStyle.Font.Size)}, Color: &xlsxColor{RGB: getPaletteColor(formatStyle.Font.Color)}, - Name: &attrValString{Val: formatStyle.Font.Family}, - Family: &attrValInt{Val: 2}, + Name: &attrValString{Val: stringPtr(formatStyle.Font.Family)}, + Family: &attrValInt{Val: intPtr(2)}, } if formatStyle.Font.Bold { fnt.B = &formatStyle.Font.Bold @@ -1998,8 +1998,8 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { if formatStyle.Font.Italic { fnt.I = &formatStyle.Font.Italic } - if fnt.Name.Val == "" { - fnt.Name.Val = f.GetDefaultFont() + if *fnt.Name.Val == "" { + *fnt.Name.Val = f.GetDefaultFont() } if formatStyle.Font.Strike { strike := true @@ -2007,7 +2007,7 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { } val, ok := fontUnderlineType[formatStyle.Font.Underline] if ok { - fnt.U = &attrValString{Val: val} + fnt.U = &attrValString{Val: stringPtr(val)} } return &fnt } -- cgit v1.2.1 From 09485b3f9f0aefc58d51462aed65c2416205c591 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 29 Dec 2019 16:02:31 +0800 Subject: Improve code coverage unit tests --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 56c7196..272d728 100644 --- a/styles.go +++ b/styles.go @@ -1,4 +1,4 @@ -// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of // this source code is governed by a BSD-style license that can be found in // the LICENSE file. // -- cgit v1.2.1 From 5f5ec76740704a8362e5a120b4a3582b409a5fdd Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 31 Dec 2019 01:01:16 +0800 Subject: Fix #551, handle empty rows in streaming reading --- styles.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 272d728..ad3e825 100644 --- a/styles.go +++ b/styles.go @@ -2321,7 +2321,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2330,7 +2330,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2338,7 +2338,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2346,7 +2346,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2357,7 +2357,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // f.SetCellValue("Sheet1", "H9", 42920.5) // style, err := f.NewStyle(`{"number_format": 22}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2365,7 +2365,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Times New Roman","size":36,"color":"#777777"}}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2373,7 +2373,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"protection":{"hidden":true, "locked":true}}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2507,7 +2507,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error { // // format, err = f.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`) // if err != nil { -// fmt.Println(err) +// println(err.Error()) // } // f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format)) // -- cgit v1.2.1 From ad883caa0f77dfc016ae99bd5fbb606953eb99a0 Mon Sep 17 00:00:00 2001 From: xuri Date: Wed, 19 Feb 2020 00:08:10 +0800 Subject: Resolve #580, revert commit https://github.com/360EntSecGroup-Skylar/excelize/commit/5ca7231ed408ac264f509ff52b5d28ff4fbda757 --- styles.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index ad3e825..272d728 100644 --- a/styles.go +++ b/styles.go @@ -2321,7 +2321,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"border":[{"type":"left","color":"0000FF","style":3},{"type":"top","color":"00FF00","style":4},{"type":"bottom","color":"FFFF00","style":5},{"type":"right","color":"FF0000","style":6},{"type":"diagonalDown","color":"A020F0","style":7},{"type":"diagonalUp","color":"A020F0","style":8}]}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2330,7 +2330,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"fill":{"type":"gradient","color":["#FFFFFF","#E0EBF5"],"shading":1}}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2338,7 +2338,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"fill":{"type":"pattern","color":["#E0EBF5"],"pattern":1}}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2346,7 +2346,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"alignment":{"horizontal":"center","ident":1,"justify_last_line":true,"reading_order":0,"relative_indent":1,"shrink_to_fit":true,"text_rotation":45,"vertical":"","wrap_text":true}}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2357,7 +2357,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // f.SetCellValue("Sheet1", "H9", 42920.5) // style, err := f.NewStyle(`{"number_format": 22}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2365,7 +2365,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"font":{"bold":true,"italic":true,"family":"Times New Roman","size":36,"color":"#777777"}}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2373,7 +2373,7 @@ func (f *File) GetCellStyle(sheet, axis string) (int, error) { // // style, err := f.NewStyle(`{"protection":{"hidden":true, "locked":true}}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // err = f.SetCellStyle("Sheet1", "H9", "H9", style) // @@ -2507,7 +2507,7 @@ func (f *File) SetCellStyle(sheet, hcell, vcell string, styleID int) error { // // format, err = f.NewConditionalStyle(`{"font":{"color":"#9A0511"},"fill":{"type":"pattern","color":["#FEC7CE"],"pattern":1}}`) // if err != nil { -// println(err.Error()) +// fmt.Println(err) // } // f.SetConditionalFormat("Sheet1", "A1:A10", fmt.Sprintf(`[{"type":"cell","criteria":">","format":%d,"value":"6"}]`, format)) // -- cgit v1.2.1 From 1e3c85024d3bbc650c2f6a85fb075804af74720b Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 3 Mar 2020 00:15:03 +0800 Subject: Resolve #571, init remove conditional format support --- styles.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 272d728..caf2732 100644 --- a/styles.go +++ b/styles.go @@ -2676,6 +2676,22 @@ func (f *File) SetConditionalFormat(sheet, area, formatSet string) error { return err } +// UnsetConditionalFormat provides a function to unset the conditional format +// by given worksheet name and range. +func (f *File) UnsetConditionalFormat(sheet, area string) error { + ws, err := f.workSheetReader(sheet) + if err != nil { + return err + } + for i, cf := range ws.ConditionalFormatting { + if cf.SQRef == area { + ws.ConditionalFormatting = append(ws.ConditionalFormatting[:i], ws.ConditionalFormatting[i+1:]...) + return nil + } + } + return nil +} + // drawCondFmtCellIs provides a function to create conditional formatting rule // for cell value (include between, not between, equal, not equal, greater // than and less than) by given priority, criteria type and format settings. -- cgit v1.2.1 From 9e2318cefa4ebaa7bf6b1dbc95b30ad7a32366b1 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 10 Mar 2020 00:04:23 +0800 Subject: Resolve #470, export Style structs to allow create the style for cells by given JSON or structure --- styles.go | 176 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 92 insertions(+), 84 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index caf2732..175a17c 100644 --- a/styles.go +++ b/styles.go @@ -1024,16 +1024,16 @@ func (f *File) styleSheetWriter() { // parseFormatStyleSet provides a function to parse the format settings of the // cells and conditional formats. -func parseFormatStyleSet(style string) (*formatStyle, error) { - format := formatStyle{ +func parseFormatStyleSet(style string) (*Style, error) { + format := Style{ DecimalPlaces: 2, } err := json.Unmarshal([]byte(style), &format) return &format, err } -// NewStyle provides a function to create style for cells by given style -// format. Note that the color field uses RGB color code. +// NewStyle provides a function to create the style for cells by given JSON or +// structure. Note that the color field uses RGB color code. // // The following shows the border styles sorted by excelize index number: // @@ -1888,18 +1888,26 @@ func parseFormatStyleSet(style string) (*formatStyle, error) { // // f := excelize.NewFile() // f.SetCellValue("Sheet1", "A6", 42920.5) -// style, err := f.NewStyle(`{"custom_number_format": "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@"}`) +// exp := "[$-380A]dddd\\,\\ dd\" de \"mmmm\" de \"yyyy;@" +// style, err := f.NewStyle(&excelize.Style{CustomNumFmt: &exp}) // err = f.SetCellStyle("Sheet1", "A6", "A6", style) // // Cell Sheet1!A6 in the Excel Application: martes, 04 de Julio de 2017 // -func (f *File) NewStyle(style string) (int, error) { +func (f *File) NewStyle(style interface{}) (int, error) { + var fs *Style + var err error var cellXfsID, fontID, borderID, fillID int - s := f.stylesReader() - fs, err := parseFormatStyleSet(style) - if err != nil { - return cellXfsID, err + switch v := style.(type) { + case string: + fs, err = parseFormatStyleSet(v) + if err != nil { + return cellXfsID, err + } + case *Style: + fs = v } + s := f.stylesReader() numFmtID := setNumFmt(s, fs) if fs.Font != nil { @@ -1978,34 +1986,34 @@ func (f *File) readDefaultFont() *xlsxFont { // setFont provides a function to add font style by given cell format // settings. -func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { +func (f *File) setFont(style *Style) *xlsxFont { fontUnderlineType := map[string]string{"single": "single", "double": "double"} - if formatStyle.Font.Size < 1 { - formatStyle.Font.Size = 11 + if style.Font.Size < 1 { + style.Font.Size = 11 } - if formatStyle.Font.Color == "" { - formatStyle.Font.Color = "#000000" + if style.Font.Color == "" { + style.Font.Color = "#000000" } fnt := xlsxFont{ - Sz: &attrValFloat{Val: float64Ptr(formatStyle.Font.Size)}, - Color: &xlsxColor{RGB: getPaletteColor(formatStyle.Font.Color)}, - Name: &attrValString{Val: stringPtr(formatStyle.Font.Family)}, + Sz: &attrValFloat{Val: float64Ptr(style.Font.Size)}, + Color: &xlsxColor{RGB: getPaletteColor(style.Font.Color)}, + Name: &attrValString{Val: stringPtr(style.Font.Family)}, Family: &attrValInt{Val: intPtr(2)}, } - if formatStyle.Font.Bold { - fnt.B = &formatStyle.Font.Bold + if style.Font.Bold { + fnt.B = &style.Font.Bold } - if formatStyle.Font.Italic { - fnt.I = &formatStyle.Font.Italic + if style.Font.Italic { + fnt.I = &style.Font.Italic } if *fnt.Name.Val == "" { *fnt.Name.Val = f.GetDefaultFont() } - if formatStyle.Font.Strike { + if style.Font.Strike { strike := true fnt.Strike = &strike } - val, ok := fontUnderlineType[formatStyle.Font.Underline] + val, ok := fontUnderlineType[style.Font.Underline] if ok { fnt.U = &attrValString{Val: stringPtr(val)} } @@ -2014,36 +2022,36 @@ func (f *File) setFont(formatStyle *formatStyle) *xlsxFont { // setNumFmt provides a function to check if number format code in the range // of built-in values. -func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { +func setNumFmt(styleSheet *xlsxStyleSheet, style *Style) int { dp := "0." numFmtID := 164 // Default custom number format code from 164. - if formatStyle.DecimalPlaces < 0 || formatStyle.DecimalPlaces > 30 { - formatStyle.DecimalPlaces = 2 + if style.DecimalPlaces < 0 || style.DecimalPlaces > 30 { + style.DecimalPlaces = 2 } - for i := 0; i < formatStyle.DecimalPlaces; i++ { + for i := 0; i < style.DecimalPlaces; i++ { dp += "0" } - if formatStyle.CustomNumFmt != nil { - return setCustomNumFmt(style, formatStyle) + if style.CustomNumFmt != nil { + return setCustomNumFmt(styleSheet, style) } - _, ok := builtInNumFmt[formatStyle.NumFmt] + _, ok := builtInNumFmt[style.NumFmt] if !ok { - fc, currency := currencyNumFmt[formatStyle.NumFmt] + fc, currency := currencyNumFmt[style.NumFmt] if !currency { - return setLangNumFmt(style, formatStyle) + return setLangNumFmt(styleSheet, style) } fc = strings.Replace(fc, "0.00", dp, -1) - if formatStyle.NegRed { + if style.NegRed { fc = fc + ";[Red]" + fc } - if style.NumFmts != nil { - numFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1 + if styleSheet.NumFmts != nil { + numFmtID = styleSheet.NumFmts.NumFmt[len(styleSheet.NumFmts.NumFmt)-1].NumFmtID + 1 nf := xlsxNumFmt{ FormatCode: fc, NumFmtID: numFmtID, } - style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf) - style.NumFmts.Count++ + styleSheet.NumFmts.NumFmt = append(styleSheet.NumFmts.NumFmt, &nf) + styleSheet.NumFmts.Count++ } else { nf := xlsxNumFmt{ FormatCode: fc, @@ -2053,61 +2061,61 @@ func setNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { NumFmt: []*xlsxNumFmt{&nf}, Count: 1, } - style.NumFmts = &numFmts + styleSheet.NumFmts = &numFmts } return numFmtID } - return formatStyle.NumFmt + return style.NumFmt } // setCustomNumFmt provides a function to set custom number format code. -func setCustomNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { - nf := xlsxNumFmt{FormatCode: *formatStyle.CustomNumFmt} - if style.NumFmts != nil { - nf.NumFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1 - style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf) - style.NumFmts.Count++ +func setCustomNumFmt(styleSheet *xlsxStyleSheet, style *Style) int { + nf := xlsxNumFmt{FormatCode: *style.CustomNumFmt} + if styleSheet.NumFmts != nil { + nf.NumFmtID = styleSheet.NumFmts.NumFmt[len(styleSheet.NumFmts.NumFmt)-1].NumFmtID + 1 + styleSheet.NumFmts.NumFmt = append(styleSheet.NumFmts.NumFmt, &nf) + styleSheet.NumFmts.Count++ } else { nf.NumFmtID = 164 numFmts := xlsxNumFmts{ NumFmt: []*xlsxNumFmt{&nf}, Count: 1, } - style.NumFmts = &numFmts + styleSheet.NumFmts = &numFmts } return nf.NumFmtID } // setLangNumFmt provides a function to set number format code with language. -func setLangNumFmt(style *xlsxStyleSheet, formatStyle *formatStyle) int { - numFmts, ok := langNumFmt[formatStyle.Lang] +func setLangNumFmt(styleSheet *xlsxStyleSheet, style *Style) int { + numFmts, ok := langNumFmt[style.Lang] if !ok { return 0 } var fc string - fc, ok = numFmts[formatStyle.NumFmt] + fc, ok = numFmts[style.NumFmt] if !ok { return 0 } nf := xlsxNumFmt{FormatCode: fc} - if style.NumFmts != nil { - nf.NumFmtID = style.NumFmts.NumFmt[len(style.NumFmts.NumFmt)-1].NumFmtID + 1 - style.NumFmts.NumFmt = append(style.NumFmts.NumFmt, &nf) - style.NumFmts.Count++ + if styleSheet.NumFmts != nil { + nf.NumFmtID = styleSheet.NumFmts.NumFmt[len(styleSheet.NumFmts.NumFmt)-1].NumFmtID + 1 + styleSheet.NumFmts.NumFmt = append(styleSheet.NumFmts.NumFmt, &nf) + styleSheet.NumFmts.Count++ } else { - nf.NumFmtID = formatStyle.NumFmt + nf.NumFmtID = style.NumFmt numFmts := xlsxNumFmts{ NumFmt: []*xlsxNumFmt{&nf}, Count: 1, } - style.NumFmts = &numFmts + styleSheet.NumFmts = &numFmts } return nf.NumFmtID } // setFills provides a function to add fill elements in the styles.xml by // given cell format settings. -func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { +func setFills(style *Style, fg bool) *xlsxFill { var patterns = []string{ "none", "solid", @@ -2138,15 +2146,15 @@ func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { } var fill xlsxFill - switch formatStyle.Fill.Type { + switch style.Fill.Type { case "gradient": - if len(formatStyle.Fill.Color) != 2 { + if len(style.Fill.Color) != 2 { break } var gradient xlsxGradientFill - switch formatStyle.Fill.Shading { + switch style.Fill.Shading { case 0, 1, 2, 3: - gradient.Degree = variants[formatStyle.Fill.Shading] + gradient.Degree = variants[style.Fill.Shading] case 4: gradient.Type = "path" case 5: @@ -2159,7 +2167,7 @@ func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { break } var stops []*xlsxGradientFillStop - for index, color := range formatStyle.Fill.Color { + for index, color := range style.Fill.Color { var stop xlsxGradientFillStop stop.Position = float64(index) stop.Color.RGB = getPaletteColor(color) @@ -2168,18 +2176,18 @@ func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { gradient.Stop = stops fill.GradientFill = &gradient case "pattern": - if formatStyle.Fill.Pattern > 18 || formatStyle.Fill.Pattern < 0 { + if style.Fill.Pattern > 18 || style.Fill.Pattern < 0 { break } - if len(formatStyle.Fill.Color) < 1 { + if len(style.Fill.Color) < 1 { break } var pattern xlsxPatternFill - pattern.PatternType = patterns[formatStyle.Fill.Pattern] + pattern.PatternType = patterns[style.Fill.Pattern] if fg { - pattern.FgColor.RGB = getPaletteColor(formatStyle.Fill.Color[0]) + pattern.FgColor.RGB = getPaletteColor(style.Fill.Color[0]) } else { - pattern.BgColor.RGB = getPaletteColor(formatStyle.Fill.Color[0]) + pattern.BgColor.RGB = getPaletteColor(style.Fill.Color[0]) } fill.PatternFill = &pattern default: @@ -2192,36 +2200,36 @@ func setFills(formatStyle *formatStyle, fg bool) *xlsxFill { // text alignment in cells. There are a variety of choices for how text is // aligned both horizontally and vertically, as well as indentation settings, // and so on. -func setAlignment(formatStyle *formatStyle) *xlsxAlignment { +func setAlignment(style *Style) *xlsxAlignment { var alignment xlsxAlignment - if formatStyle.Alignment != nil { - alignment.Horizontal = formatStyle.Alignment.Horizontal - alignment.Indent = formatStyle.Alignment.Indent - alignment.JustifyLastLine = formatStyle.Alignment.JustifyLastLine - alignment.ReadingOrder = formatStyle.Alignment.ReadingOrder - alignment.RelativeIndent = formatStyle.Alignment.RelativeIndent - alignment.ShrinkToFit = formatStyle.Alignment.ShrinkToFit - alignment.TextRotation = formatStyle.Alignment.TextRotation - alignment.Vertical = formatStyle.Alignment.Vertical - alignment.WrapText = formatStyle.Alignment.WrapText + if style.Alignment != nil { + alignment.Horizontal = style.Alignment.Horizontal + alignment.Indent = style.Alignment.Indent + alignment.JustifyLastLine = style.Alignment.JustifyLastLine + alignment.ReadingOrder = style.Alignment.ReadingOrder + alignment.RelativeIndent = style.Alignment.RelativeIndent + alignment.ShrinkToFit = style.Alignment.ShrinkToFit + alignment.TextRotation = style.Alignment.TextRotation + alignment.Vertical = style.Alignment.Vertical + alignment.WrapText = style.Alignment.WrapText } return &alignment } // setProtection provides a function to set protection properties associated // with the cell. -func setProtection(formatStyle *formatStyle) *xlsxProtection { +func setProtection(style *Style) *xlsxProtection { var protection xlsxProtection - if formatStyle.Protection != nil { - protection.Hidden = formatStyle.Protection.Hidden - protection.Locked = formatStyle.Protection.Locked + if style.Protection != nil { + protection.Hidden = style.Protection.Hidden + protection.Locked = style.Protection.Locked } return &protection } // setBorders provides a function to add border elements in the styles.xml by // given borders format settings. -func setBorders(formatStyle *formatStyle) *xlsxBorder { +func setBorders(style *Style) *xlsxBorder { var styles = []string{ "none", "thin", @@ -2240,7 +2248,7 @@ func setBorders(formatStyle *formatStyle) *xlsxBorder { } var border xlsxBorder - for _, v := range formatStyle.Border { + for _, v := range style.Border { if 0 <= v.Style && v.Style < 14 { var color xlsxColor color.RGB = getPaletteColor(v.Color) -- cgit v1.2.1 From cea3d806ecbec5027a8f0d7f10b700707131a7be Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 16 Mar 2020 00:13:01 +0800 Subject: Resolve #200, ignore empty conditional format style --- styles.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 175a17c..f2171bb 100644 --- a/styles.go +++ b/styles.go @@ -1943,9 +1943,13 @@ func (f *File) NewConditionalStyle(style string) (int, error) { return 0, err } dxf := dxf{ - Fill: setFills(fs, false), - Alignment: setAlignment(fs), - Border: setBorders(fs), + Fill: setFills(fs, false), + } + if fs.Alignment != nil { + dxf.Alignment = setAlignment(fs) + } + if len(fs.Border) > 0 { + dxf.Border = setBorders(fs) } if fs.Font != nil { dxf.Font = f.setFont(fs) -- cgit v1.2.1 From 6afc468a025984aa1b265b0228f032c5ed881a3b Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 28 Mar 2020 23:47:26 +0800 Subject: Resolve #451, support create chart sheet --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index f2171bb..8d8b464 100644 --- a/styles.go +++ b/styles.go @@ -1018,7 +1018,7 @@ func (f *File) stylesReader() *xlsxStyleSheet { func (f *File) styleSheetWriter() { if f.Styles != nil { output, _ := xml.Marshal(f.Styles) - f.saveFileList("xl/styles.xml", replaceStyleRelationshipsNameSpaceBytes(output)) + f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpaceBytes(output)) } } -- cgit v1.2.1 From 3f89c6e9799c9c82af1305f080416c53d19e64c1 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 29 Mar 2020 18:44:24 +0800 Subject: remove ineffectual variable assignments and simplify code --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 8d8b464..9cf974e 100644 --- a/styles.go +++ b/styles.go @@ -1018,7 +1018,7 @@ func (f *File) stylesReader() *xlsxStyleSheet { func (f *File) styleSheetWriter() { if f.Styles != nil { output, _ := xml.Marshal(f.Styles) - f.saveFileList("xl/styles.xml", replaceWorkSheetsRelationshipsNameSpaceBytes(output)) + f.saveFileList("xl/styles.xml", replaceRelationshipsNameSpaceBytes(output)) } } -- cgit v1.2.1 From 66d0272f6af59b5f0c97a304379a795420a43e8b Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 6 Apr 2020 00:23:27 +0800 Subject: Resolve #172, init rich text support --- styles.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 9cf974e..fe2bed5 100644 --- a/styles.go +++ b/styles.go @@ -13,6 +13,7 @@ import ( "bytes" "encoding/json" "encoding/xml" + "errors" "fmt" "io" "log" @@ -1022,6 +1023,15 @@ func (f *File) styleSheetWriter() { } } +// sharedStringsWriter provides a function to save xl/sharedStrings.xml after +// serialize structure. +func (f *File) sharedStringsWriter() { + if f.SharedStrings != nil { + output, _ := xml.Marshal(f.SharedStrings) + f.saveFileList("xl/sharedStrings.xml", replaceRelationshipsNameSpaceBytes(output)) + } +} + // parseFormatStyleSet provides a function to parse the format settings of the // cells and conditional formats. func parseFormatStyleSet(style string) (*Style, error) { @@ -1033,7 +1043,7 @@ func parseFormatStyleSet(style string) (*Style, error) { } // NewStyle provides a function to create the style for cells by given JSON or -// structure. Note that the color field uses RGB color code. +// structure pointer. Note that the color field uses RGB color code. // // The following shows the border styles sorted by excelize index number: // @@ -1906,6 +1916,8 @@ func (f *File) NewStyle(style interface{}) (int, error) { } case *Style: fs = v + default: + return cellXfsID, errors.New("invalid parameter type") } s := f.stylesReader() numFmtID := setNumFmt(s, fs) -- cgit v1.2.1 From a2e1da8d9d90ed71a33523cfe2c5231cd0b5fad9 Mon Sep 17 00:00:00 2001 From: echarlus Date: Wed, 8 Apr 2020 18:50:20 +0200 Subject: Fix for issue #608 (#609) --- styles.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index fe2bed5..61b8e53 100644 --- a/styles.go +++ b/styles.go @@ -2732,7 +2732,7 @@ func drawCondFmtCellIs(p int, ct string, format *formatConditional) *xlsxCfRule c.Formula = append(c.Formula, format.Minimum) c.Formula = append(c.Formula, format.Maximum) } - _, ok = map[string]bool{"equal": true, "notEqual": true, "greaterThan": true, "lessThan": true}[ct] + _, ok = map[string]bool{"equal": true, "notEqual": true, "greaterThan": true, "lessThan": true, "greaterThanOrEqual": true, "lessThanOrEqual": true, "containsText": true, "notContains": true, "beginsWith": true, "endsWith": true}[ct] if ok { c.Formula = append(c.Formula, format.Value) } -- cgit v1.2.1 From 882abb80988b7c50286dd2e6c6589fab10662db6 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 10 May 2020 16:56:08 +0800 Subject: - formula engine: reduce cyclomatic complexity - styles: allow empty and default cell formats, #628 --- styles.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'styles.go') diff --git a/styles.go b/styles.go index 61b8e53..72b2071 100644 --- a/styles.go +++ b/styles.go @@ -2299,21 +2299,21 @@ func setBorders(style *Style) *xlsxBorder { // cell. func setCellXfs(style *xlsxStyleSheet, fontID, numFmtID, fillID, borderID int, applyAlignment, applyProtection bool, alignment *xlsxAlignment, protection *xlsxProtection) int { var xf xlsxXf - xf.FontID = fontID + xf.FontID = intPtr(fontID) if fontID != 0 { - xf.ApplyFont = true + xf.ApplyFont = boolPtr(true) } - xf.NumFmtID = numFmtID + xf.NumFmtID = intPtr(numFmtID) if numFmtID != 0 { - xf.ApplyNumberFormat = true + xf.ApplyNumberFormat = boolPtr(true) } - xf.FillID = fillID - xf.BorderID = borderID + xf.FillID = intPtr(fillID) + xf.BorderID = intPtr(borderID) style.CellXfs.Count++ xf.Alignment = alignment - xf.ApplyAlignment = applyAlignment + xf.ApplyAlignment = boolPtr(applyAlignment) if applyProtection { - xf.ApplyProtection = applyProtection + xf.ApplyProtection = boolPtr(applyProtection) xf.Protection = protection } xfID := 0 -- cgit v1.2.1