From 4a1b4064568189d6f819f5fe19ff9bf6d6e8de95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Fri, 17 Nov 2017 12:56:58 +0100 Subject: CopySheet() using reflect instead of encoding/gob Use github.com/mohae/deepcopy to deep copy worksheets instead of the internal deepcopy function that was using encoding/gob serialization and deserialization. Rationale: 1/ using `encoding/gob` is much slower than [`mohae/deepcopy`](https://github.com/mohae/deepcopy/) 2/ When building an application this implementation of `deepcopy` drags the `encoding/gob` package into the binary. And this package is much bigger than `mohae/deepcopy` (which only depends on `time` and `reflect`). ``` $ LC_ALL=C stat -f "%6z %N" $(go env GOPATH)/pkg/$(go env GOOS)_$(go env GOARCH)/github.com/mohae/deepcopy.a $(go env GOROOT)/pkg/$(go env GOOS)_$(go env GOARCH)/encoding/gob.a 10508 .../pkg/darwin_amd64/github.com/mohae/deepcopy.a 541818 .../pkg/darwin_amd64/encoding/gob.a ``` --- excelize_test.go | 1 - 1 file changed, 1 deletion(-) (limited to 'excelize_test.go') diff --git a/excelize_test.go b/excelize_test.go index 4dbc709..aca33b4 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -88,7 +88,6 @@ func TestOpenFile(t *testing.T) { xlsx.SetCellValue("Sheet2", "F16", true) xlsx.SetCellValue("Sheet2", "F17", complex64(5+10i)) t.Log(letterOnlyMapF('x')) - t.Log(deepCopy(nil, nil)) shiftJulianToNoon(1, -0.6) timeFromExcelTime(61, true) timeFromExcelTime(62, true) -- cgit v1.2.1 From 1a953b6601df2484a39203edff59943e41e3f438 Mon Sep 17 00:00:00 2001 From: Rad Cirskis Date: Sat, 30 Jun 2018 22:55:14 +1200 Subject: added unit tests --- excelize_test.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'excelize_test.go') diff --git a/excelize_test.go b/excelize_test.go index aca33b4..0bcb16d 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -816,6 +816,11 @@ func TestAddComments(t *testing.T) { if err != nil { t.Error(err) } + allComments := xlsx.GetComments() + if len(allComments) != 2 { + t.Error("Expected 2 comment entry elements.") + } + } func TestAutoFilter(t *testing.T) { -- cgit v1.2.1 From d6468fc114217678e8bc8b4324fd6185794e0182 Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 7 Jul 2018 15:59:48 +0800 Subject: - Initialize theme support; - RGBA, HSL color convert has been added; - go test updated --- excelize_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'excelize_test.go') diff --git a/excelize_test.go b/excelize_test.go index aca33b4..549190c 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -2,6 +2,7 @@ package excelize import ( "fmt" + "image/color" _ "image/gif" _ "image/jpeg" _ "image/png" @@ -1145,6 +1146,31 @@ func TestOutlineLevel(t *testing.T) { xlsx.SetColOutlineLevel("Sheet2", "B", 2) } +func TestThemeColor(t *testing.T) { + t.Log(ThemeColor("000000", -0.1)) + t.Log(ThemeColor("000000", 0)) + t.Log(ThemeColor("000000", 1)) +} + +func TestHSL(t *testing.T) { + var hsl HSL + t.Log(hsl.RGBA()) + t.Log(hslModel(hsl)) + t.Log(hslModel(color.Gray16{Y: uint16(1)})) + t.Log(HSLToRGB(0, 1, 0.4)) + t.Log(HSLToRGB(0, 1, 0.6)) + t.Log(hueToRGB(0, 0, -1)) + t.Log(hueToRGB(0, 0, 2)) + t.Log(hueToRGB(0, 0, 1.0/7)) + t.Log(hueToRGB(0, 0, 0.4)) + t.Log(hueToRGB(0, 0, 2.0/4)) + t.Log(RGBToHSL(255, 255, 0)) + t.Log(RGBToHSL(0, 255, 255)) + t.Log(RGBToHSL(250, 100, 50)) + t.Log(RGBToHSL(50, 100, 250)) + t.Log(RGBToHSL(250, 50, 100)) +} + func trimSliceSpace(s []string) []string { for { if len(s) > 0 && s[len(s)-1] == "" { -- cgit v1.2.1 From a3571ee39bec82d15d9a183aed7f7db39e0a160f Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 17 Jul 2018 15:28:22 +0800 Subject: Bugfix: create worksheet cause file issue. Relate issue #249. --- excelize_test.go | 4 ---- 1 file changed, 4 deletions(-) (limited to 'excelize_test.go') diff --git a/excelize_test.go b/excelize_test.go index 94732fe..c9a87d0 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -771,10 +771,6 @@ func TestAddTable(t *testing.T) { if err != nil { t.Error(err) } - err = xlsx.AddTable("Sheet2", "A2", "B5", ``) - if err != nil { - t.Log(err) - } err = xlsx.AddTable("Sheet2", "A2", "B5", `{"table_name":"table","table_style":"TableStyleMedium2", "show_first_column":true,"show_last_column":true,"show_row_stripes":false,"show_column_stripes":true}`) if err != nil { t.Error(err) -- cgit v1.2.1 From 6ced438f39030e8a9a521548d4112dd002dc2ebe Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 14 Sep 2018 00:24:49 +0800 Subject: New function `AddPictureFromBytes()` has been added, this resolve #259 and close #271. --- excelize_test.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'excelize_test.go') diff --git a/excelize_test.go b/excelize_test.go index c9a87d0..9f738f3 100644 --- a/excelize_test.go +++ b/excelize_test.go @@ -162,6 +162,24 @@ func TestAddPicture(t *testing.T) { if err != nil { t.Log(err) } + err = xlsx.AddPictureFromBytes("Sheet1", "G21", "", "Excel Logo", "jpg", make([]byte, 1)) + if err != nil { + t.Log(err) + } + // Test add picture to worksheet with invalid file data. + err = xlsx.AddPictureFromBytes("Sheet1", "G21", "", "Excel Logo", ".jpg", make([]byte, 1)) + if err != nil { + t.Log(err) + } + file, err := ioutil.ReadFile("./test/images/excel.jpg") + if err != nil { + t.Error(err) + } + // Test add picture to worksheet from bytes. + err = xlsx.AddPictureFromBytes("Sheet1", "Q1", "", "Excel Logo", ".jpg", file) + if err != nil { + t.Log(err) + } // Test write file to given path. err = xlsx.SaveAs("./test/Book2.xlsx") if err != nil { @@ -211,8 +229,13 @@ func TestNewFile(t *testing.T) { if err != nil { t.Error(err) } - // Test add picture to worksheet with invalid formatset + // Test add picture to worksheet without formatset. err = xlsx.AddPicture("Sheet1", "C2", "./test/images/excel.png", "") + if err != nil { + t.Error(err) + } + // Test add picture to worksheet with invalid formatset. + err = xlsx.AddPicture("Sheet1", "C2", "./test/images/excel.png", `{`) if err != nil { t.Log(err) } -- cgit v1.2.1