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 --- cell_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index d4a5b02..09627c2 100644 --- a/cell_test.go +++ b/cell_test.go @@ -2,6 +2,7 @@ package excelize import ( "fmt" + "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -94,3 +95,15 @@ func BenchmarkSetCellValue(b *testing.B) { } } } + +func TestOverflowNumericCell(t *testing.T) { + f, err := OpenFile(filepath.Join("test", "OverflowNumericCell.xlsx")) + if !assert.NoError(t, err) { + t.FailNow() + } + // source of xlsx file is Russia, don`t touch it, elsewhere bug not reproduced + val, err := f.GetCellValue("Лист1", "A1") + assert.NoError(t, err) + // GOARCH=amd64 - all ok; GOARCH=386 - actual : "-2147483648" + assert.Equal(t, "8595602512225", val, "A1 should be 8595602512225") +} -- cgit v1.2.1 From 0acb3ef9685e80d51dfda5ab9a9db870af7e1614 Mon Sep 17 00:00:00 2001 From: xuri Date: Mon, 2 Sep 2019 21:52:55 +0800 Subject: Testing files updated --- cell_test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index 09627c2..653aaab 100644 --- a/cell_test.go +++ b/cell_test.go @@ -101,9 +101,8 @@ func TestOverflowNumericCell(t *testing.T) { if !assert.NoError(t, err) { t.FailNow() } - // source of xlsx file is Russia, don`t touch it, elsewhere bug not reproduced - val, err := f.GetCellValue("Лист1", "A1") + val, err := f.GetCellValue("Sheet1", "A1") assert.NoError(t, err) - // GOARCH=amd64 - all ok; GOARCH=386 - actual : "-2147483648" + // GOARCH=amd64 - all ok; GOARCH=386 - actual: "-2147483648" assert.Equal(t, "8595602512225", val, "A1 should be 8595602512225") } -- cgit v1.2.1 From 5e418ebd665f38d1211b27d7157ec7e5868451bc Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 26 Oct 2019 20:55:24 +0800 Subject: Resolve #507, add the new function `DeleteDefinedName` --- cell_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index 653aaab..da0c1f1 100644 --- a/cell_test.go +++ b/cell_test.go @@ -4,6 +4,7 @@ import ( "fmt" "path/filepath" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -73,6 +74,50 @@ func TestSetCellFloat(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "123.42", val, "A1 should be 123.42") }) + f := NewFile() + assert.EqualError(t, f.SetCellFloat(sheet, "A", 123.42, -1, 64), `cannot convert cell "A" to coordinates: invalid cell name "A"`) +} + +func TestSetCellValue(t *testing.T) { + f := NewFile() + assert.EqualError(t, f.SetCellValue("Sheet1", "A", time.Now().UTC()), `cannot convert cell "A" to coordinates: invalid cell name "A"`) + assert.EqualError(t, f.SetCellValue("Sheet1", "A", time.Duration(1e13)), `cannot convert cell "A" to coordinates: invalid cell name "A"`) +} + +func TestSetCellBool(t *testing.T) { + f := NewFile() + assert.EqualError(t, f.SetCellBool("Sheet1", "A", true), `cannot convert cell "A" to coordinates: invalid cell name "A"`) +} + +func TestGetCellFormula(t *testing.T) { + f := NewFile() + f.GetCellFormula("Sheet", "A1") +} + +func TestMergeCell(t *testing.T) { + f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) + if !assert.NoError(t, err) { + t.FailNow() + } + assert.EqualError(t, f.MergeCell("Sheet1", "A", "B"), `cannot convert cell "A" to coordinates: invalid cell name "A"`) + f.MergeCell("Sheet1", "D9", "D9") + f.MergeCell("Sheet1", "D9", "E9") + f.MergeCell("Sheet1", "H14", "G13") + f.MergeCell("Sheet1", "C9", "D8") + f.MergeCell("Sheet1", "F11", "G13") + f.MergeCell("Sheet1", "H7", "B15") + f.MergeCell("Sheet1", "D11", "F13") + f.MergeCell("Sheet1", "G10", "K12") + f.SetCellValue("Sheet1", "G11", "set value in merged cell") + f.SetCellInt("Sheet1", "H11", 100) + f.SetCellValue("Sheet1", "I11", float64(0.5)) + f.SetCellHyperLink("Sheet1", "J11", "https://github.com/360EntSecGroup-Skylar/excelize", "External") + f.SetCellFormula("Sheet1", "G12", "SUM(Sheet1!B19,Sheet1!C19)") + f.GetCellValue("Sheet1", "H11") + f.GetCellValue("Sheet2", "A6") // Merged cell ref is single coordinate. + f.GetCellFormula("Sheet1", "G12") + + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestMergeCell.xlsx"))) } func ExampleFile_SetCellFloat() { -- cgit v1.2.1 From da0d2ffbb6ebdfb7b1e5cf501a1986421311017b Mon Sep 17 00:00:00 2001 From: xuri Date: Sat, 14 Dec 2019 19:57:37 +0800 Subject: Fix #533, add support overlapped mergecells --- cell_test.go | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index da0c1f1..b030622 100644 --- a/cell_test.go +++ b/cell_test.go @@ -10,6 +10,7 @@ import ( ) func TestCheckCellInArea(t *testing.T) { + f := NewFile() expectedTrueCellInAreaList := [][2]string{ {"c2", "A1:AAZ32"}, {"B9", "A1:B9"}, @@ -19,7 +20,7 @@ func TestCheckCellInArea(t *testing.T) { for _, expectedTrueCellInArea := range expectedTrueCellInAreaList { cell := expectedTrueCellInArea[0] area := expectedTrueCellInArea[1] - ok, err := checkCellInArea(cell, area) + ok, err := f.checkCellInArea(cell, area) assert.NoError(t, err) assert.Truef(t, ok, "Expected cell %v to be in area %v, got false\n", cell, area) @@ -34,13 +35,17 @@ func TestCheckCellInArea(t *testing.T) { for _, expectedFalseCellInArea := range expectedFalseCellInAreaList { cell := expectedFalseCellInArea[0] area := expectedFalseCellInArea[1] - ok, err := checkCellInArea(cell, area) + ok, err := f.checkCellInArea(cell, area) assert.NoError(t, err) assert.Falsef(t, ok, "Expected cell %v not to be inside of area %v, but got true\n", cell, area) } - ok, err := checkCellInArea("AA0", "Z0:AB1") + ok, err := f.checkCellInArea("A1", "A:B") + assert.EqualError(t, err, `cannot convert cell "A" to coordinates: invalid cell name "A"`) + assert.False(t, ok) + + ok, err = f.checkCellInArea("AA0", "Z0:AB1") assert.EqualError(t, err, `cannot convert cell "AA0" to coordinates: invalid cell name "AA0"`) assert.False(t, ok) } @@ -94,32 +99,6 @@ func TestGetCellFormula(t *testing.T) { f.GetCellFormula("Sheet", "A1") } -func TestMergeCell(t *testing.T) { - f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) - if !assert.NoError(t, err) { - t.FailNow() - } - assert.EqualError(t, f.MergeCell("Sheet1", "A", "B"), `cannot convert cell "A" to coordinates: invalid cell name "A"`) - f.MergeCell("Sheet1", "D9", "D9") - f.MergeCell("Sheet1", "D9", "E9") - f.MergeCell("Sheet1", "H14", "G13") - f.MergeCell("Sheet1", "C9", "D8") - f.MergeCell("Sheet1", "F11", "G13") - f.MergeCell("Sheet1", "H7", "B15") - f.MergeCell("Sheet1", "D11", "F13") - f.MergeCell("Sheet1", "G10", "K12") - f.SetCellValue("Sheet1", "G11", "set value in merged cell") - f.SetCellInt("Sheet1", "H11", 100) - f.SetCellValue("Sheet1", "I11", float64(0.5)) - f.SetCellHyperLink("Sheet1", "J11", "https://github.com/360EntSecGroup-Skylar/excelize", "External") - f.SetCellFormula("Sheet1", "G12", "SUM(Sheet1!B19,Sheet1!C19)") - f.GetCellValue("Sheet1", "H11") - f.GetCellValue("Sheet2", "A6") // Merged cell ref is single coordinate. - f.GetCellFormula("Sheet1", "G12") - - assert.NoError(t, f.SaveAs(filepath.Join("test", "TestMergeCell.xlsx"))) -} - func ExampleFile_SetCellFloat() { f := NewFile() var x = 3.14159265 -- cgit v1.2.1 From ae2865d9237cfd27d7bc4fbef3870b3361597be8 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 22 Dec 2019 00:02:09 +0800 Subject: Improve code coverage unit tests --- cell_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index b030622..7d3339f 100644 --- a/cell_test.go +++ b/cell_test.go @@ -95,8 +95,15 @@ func TestSetCellBool(t *testing.T) { } func TestGetCellFormula(t *testing.T) { + // Test get cell formula on not exist worksheet. f := NewFile() - f.GetCellFormula("Sheet", "A1") + _, err := f.GetCellFormula("SheetN", "A1") + assert.EqualError(t, err, "sheet SheetN is not exist") + + // Test get cell formula on no formula cell. + f.SetCellValue("Sheet1", "A1", true) + _, err = f.GetCellFormula("Sheet1", "A1") + assert.NoError(t, err) } func ExampleFile_SetCellFloat() { -- cgit v1.2.1 From 1666d04559d9f5b579ab7c850ccc95863c31bd25 Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 24 Dec 2019 01:09:28 +0800 Subject: optimization: checking error in unit tests --- cell_test.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index 7d3339f..1efbc5a 100644 --- a/cell_test.go +++ b/cell_test.go @@ -54,8 +54,8 @@ func TestSetCellFloat(t *testing.T) { sheet := "Sheet1" t.Run("with no decimal", func(t *testing.T) { f := NewFile() - f.SetCellFloat(sheet, "A1", 123.0, -1, 64) - f.SetCellFloat(sheet, "A2", 123.0, 1, 64) + assert.NoError(t, f.SetCellFloat(sheet, "A1", 123.0, -1, 64)) + assert.NoError(t, f.SetCellFloat(sheet, "A2", 123.0, 1, 64)) val, err := f.GetCellValue(sheet, "A1") assert.NoError(t, err) assert.Equal(t, "123", val, "A1 should be 123") @@ -66,7 +66,7 @@ func TestSetCellFloat(t *testing.T) { t.Run("with a decimal and precision limit", func(t *testing.T) { f := NewFile() - f.SetCellFloat(sheet, "A1", 123.42, 1, 64) + assert.NoError(t, f.SetCellFloat(sheet, "A1", 123.42, 1, 64)) val, err := f.GetCellValue(sheet, "A1") assert.NoError(t, err) assert.Equal(t, "123.4", val, "A1 should be 123.4") @@ -74,7 +74,7 @@ func TestSetCellFloat(t *testing.T) { t.Run("with a decimal and no limit", func(t *testing.T) { f := NewFile() - f.SetCellFloat(sheet, "A1", 123.42, -1, 64) + assert.NoError(t, f.SetCellFloat(sheet, "A1", 123.42, -1, 64)) val, err := f.GetCellValue(sheet, "A1") assert.NoError(t, err) assert.Equal(t, "123.42", val, "A1 should be 123.42") @@ -101,7 +101,7 @@ func TestGetCellFormula(t *testing.T) { assert.EqualError(t, err, "sheet SheetN is not exist") // Test get cell formula on no formula cell. - f.SetCellValue("Sheet1", "A1", true) + assert.NoError(t, f.SetCellValue("Sheet1", "A1", true)) _, err = f.GetCellFormula("Sheet1", "A1") assert.NoError(t, err) } @@ -109,7 +109,9 @@ func TestGetCellFormula(t *testing.T) { func ExampleFile_SetCellFloat() { f := NewFile() var x = 3.14159265 - f.SetCellFloat("Sheet1", "A1", x, 2, 64) + if err := f.SetCellFloat("Sheet1", "A1", x, 2, 64); err != nil { + fmt.Println(err) + } val, _ := f.GetCellValue("Sheet1", "A1") fmt.Println(val) // Output: 3.14 @@ -122,7 +124,9 @@ func BenchmarkSetCellValue(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { for j := 0; j < len(values); j++ { - f.SetCellValue("Sheet1", fmt.Sprint(cols[j], i), values[j]) + if err := f.SetCellValue("Sheet1", fmt.Sprint(cols[j], i), values[j]); err != nil { + b.Error(err) + } } } } -- cgit v1.2.1 From 5ca7231ed408ac264f509ff52b5d28ff4fbda757 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 3 Jan 2020 23:57:25 +0800 Subject: optimize code and comments: use println errors instead of panic --- cell_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index 1efbc5a..60f8751 100644 --- a/cell_test.go +++ b/cell_test.go @@ -110,7 +110,7 @@ func ExampleFile_SetCellFloat() { f := NewFile() var x = 3.14159265 if err := f.SetCellFloat("Sheet1", "A1", x, 2, 64); err != nil { - fmt.Println(err) + println(err.Error()) } val, _ := f.GetCellValue("Sheet1", "A1") fmt.Println(val) -- 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 --- cell_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index 60f8751..1efbc5a 100644 --- a/cell_test.go +++ b/cell_test.go @@ -110,7 +110,7 @@ func ExampleFile_SetCellFloat() { f := NewFile() var x = 3.14159265 if err := f.SetCellFloat("Sheet1", "A1", x, 2, 64); err != nil { - println(err.Error()) + fmt.Println(err) } val, _ := f.GetCellValue("Sheet1", "A1") fmt.Println(val) -- 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 --- cell_test.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index 1efbc5a..f46b4b9 100644 --- a/cell_test.go +++ b/cell_test.go @@ -141,3 +141,84 @@ func TestOverflowNumericCell(t *testing.T) { // GOARCH=amd64 - all ok; GOARCH=386 - actual: "-2147483648" assert.Equal(t, "8595602512225", val, "A1 should be 8595602512225") } + +func TestSetCellRichText(t *testing.T) { + f := NewFile() + assert.NoError(t, f.SetRowHeight("Sheet1", 1, 35)) + assert.NoError(t, f.SetColWidth("Sheet1", "A", "A", 44)) + richTextRun := []RichTextRun{ + { + Text: "blod", + Font: &Font{ + Bold: true, + Color: "2354e8", + Family: "Times New Roman", + }, + }, + { + Text: " and ", + Font: &Font{ + Family: "Times New Roman", + }, + }, + { + Text: "italic ", + Font: &Font{ + Bold: true, + Color: "e83723", + Italic: true, + Family: "Times New Roman", + }, + }, + { + Text: "text with color and font-family,", + Font: &Font{ + Bold: true, + Color: "2354e8", + Family: "Times New Roman", + }, + }, + { + Text: "\r\nlarge text with ", + Font: &Font{ + Size: 14, + Color: "ad23e8", + }, + }, + { + Text: "strike", + Font: &Font{ + Color: "e89923", + Strike: true, + }, + }, + { + Text: " and ", + Font: &Font{ + Size: 14, + Color: "ad23e8", + }, + }, + { + Text: "underline.", + Font: &Font{ + Color: "23e833", + Underline: "single", + }, + }, + } + assert.NoError(t, f.SetCellRichText("Sheet1", "A1", richTextRun)) + assert.NoError(t, f.SetCellRichText("Sheet1", "A2", richTextRun)) + style, err := f.NewStyle(&Style{ + Alignment: &Alignment{ + WrapText: true, + }, + }) + assert.NoError(t, err) + assert.NoError(t, f.SetCellStyle("Sheet1", "A1", "A1", style)) + assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellRichText.xlsx"))) + // Test set cell rich text on not exists worksheet + assert.EqualError(t, f.SetCellRichText("SheetN", "A1", richTextRun), "sheet SheetN is not exist") + // Test set cell rich text with illegal cell coordinates + assert.EqualError(t, f.SetCellRichText("Sheet1", "A", richTextRun), `cannot convert cell "A" to coordinates: invalid cell name "A"`) +} -- cgit v1.2.1 From 10115b5d889bb229d8707803b9413b20fe798588 Mon Sep 17 00:00:00 2001 From: xuri Date: Fri, 10 Apr 2020 00:04:23 +0800 Subject: - Resolve #611, fix failure BenchmarkSetCellValue - Allow empty filter, data, and rows in the pivot table - Add more test case for pivot table --- cell_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'cell_test.go') diff --git a/cell_test.go b/cell_test.go index f46b4b9..45e2f24 100644 --- a/cell_test.go +++ b/cell_test.go @@ -3,6 +3,7 @@ package excelize import ( "fmt" "path/filepath" + "strconv" "testing" "time" @@ -122,9 +123,9 @@ func BenchmarkSetCellValue(b *testing.B) { cols := []string{"A", "B", "C", "D", "E", "F"} f := NewFile() b.ResetTimer() - for i := 0; i < b.N; i++ { + for i := 1; i <= b.N; i++ { for j := 0; j < len(values); j++ { - if err := f.SetCellValue("Sheet1", fmt.Sprint(cols[j], i), values[j]); err != nil { + if err := f.SetCellValue("Sheet1", cols[j]+strconv.Itoa(i), values[j]); err != nil { b.Error(err) } } -- cgit v1.2.1