summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--README_zh.md8
-rw-r--r--calc.go29
-rw-r--r--calc_test.go14
-rw-r--r--cell.go2
-rw-r--r--chart.go4
-rw-r--r--picture.go4
-rw-r--r--pivotTable.go2
8 files changed, 57 insertions, 14 deletions
diff --git a/README.md b/README.md
index 6afcc7e..4dbf532 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ package main
import (
"fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
@@ -68,7 +68,7 @@ package main
import (
"fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
@@ -107,7 +107,7 @@ package main
import (
"fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
@@ -142,7 +142,7 @@ import (
_ "image/jpeg"
_ "image/png"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
diff --git a/README_zh.md b/README_zh.md
index f54cf01..25b2fbf 100644
--- a/README_zh.md
+++ b/README_zh.md
@@ -39,7 +39,7 @@ package main
import (
"fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
@@ -68,7 +68,7 @@ package main
import (
"fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
@@ -107,7 +107,7 @@ package main
import (
"fmt"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
@@ -142,7 +142,7 @@ import (
_ "image/jpeg"
_ "image/png"
- "github.com/360EntSecGroup-Skylar/excelize"
+ "github.com/360EntSecGroup-Skylar/excelize/v2"
)
func main() {
diff --git a/calc.go b/calc.go
index 577cfaa..7da2493 100644
--- a/calc.go
+++ b/calc.go
@@ -3365,3 +3365,32 @@ func makeDate(y int, m time.Month, d int) int64 {
func daysBetween(startDate, endDate int64) float64 {
return float64(int(0.5 + float64((endDate-startDate)/86400)))
}
+
+// Text Functions
+
+// CLEAN removes all non-printable characters from a supplied text string.
+func (fn *formulaFuncs) CLEAN(argsList *list.List) (result string, err error) {
+ if argsList.Len() != 1 {
+ err = errors.New("CLEAN requires 1 argument")
+ return
+ }
+ b := bytes.Buffer{}
+ for _, c := range argsList.Front().Value.(formulaArg).String {
+ if c > 31 {
+ b.WriteRune(c)
+ }
+ }
+ result = b.String()
+ return
+}
+
+// TRIM removes extra spaces (i.e. all spaces except for single spaces between
+// words or characters) from a supplied text string.
+func (fn *formulaFuncs) TRIM(argsList *list.List) (result string, err error) {
+ if argsList.Len() != 1 {
+ err = errors.New("TRIM requires 1 argument")
+ return
+ }
+ result = strings.TrimSpace(argsList.Front().Value.(formulaArg).String)
+ return
+}
diff --git a/calc_test.go b/calc_test.go
index 6998b77..f928797 100644
--- a/calc_test.go
+++ b/calc_test.go
@@ -463,6 +463,13 @@ func TestCalcCellValue(t *testing.T) {
// DATE
"=DATE(2020,10,21)": "2020-10-21 00:00:00 +0000 UTC",
"=DATE(1900,1,1)": "1899-12-31 00:00:00 +0000 UTC",
+ // Text Functions
+ // CLEAN
+ "=CLEAN(\"\u0009clean text\")": "clean text",
+ "=CLEAN(0)": "0",
+ // TRIM
+ "=TRIM(\" trim text \")": "trim text",
+ "=TRIM(0)": "0",
}
for formula, expected := range mathCalc {
f := prepareData()
@@ -779,6 +786,13 @@ func TestCalcCellValue(t *testing.T) {
`=DATE("text",10,21)`: "DATE requires 3 number arguments",
`=DATE(2020,"text",21)`: "DATE requires 3 number arguments",
`=DATE(2020,10,"text")`: "DATE requires 3 number arguments",
+ // Text Functions
+ // CLEAN
+ "=CLEAN()": "CLEAN requires 1 argument",
+ "=CLEAN(1,2)": "CLEAN requires 1 argument",
+ // TRIM
+ "=TRIM()": "TRIM requires 1 argument",
+ "=TRIM(1,2)": "TRIM requires 1 argument",
}
for formula, expected := range mathCalcError {
f := prepareData()
diff --git a/cell.go b/cell.go
index 22adefd..4dd2830 100644
--- a/cell.go
+++ b/cell.go
@@ -502,7 +502,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
// import (
// "fmt"
//
-// "github.com/360EntSecGroup-Skylar/excelize"
+// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {
diff --git a/chart.go b/chart.go
index 57f7838..32c8d71 100644
--- a/chart.go
+++ b/chart.go
@@ -510,7 +510,7 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// import (
// "fmt"
//
-// "github.com/360EntSecGroup-Skylar/excelize"
+// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {
@@ -708,7 +708,7 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
// import (
// "fmt"
//
-// "github.com/360EntSecGroup-Skylar/excelize"
+// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {
diff --git a/picture.go b/picture.go
index 6adfa71..1a9cac1 100644
--- a/picture.go
+++ b/picture.go
@@ -55,7 +55,7 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
// _ "image/jpeg"
// _ "image/png"
//
-// "github.com/360EntSecGroup-Skylar/excelize"
+// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {
@@ -111,7 +111,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
// _ "image/jpeg"
// "io/ioutil"
//
-// "github.com/360EntSecGroup-Skylar/excelize"
+// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {
diff --git a/pivotTable.go b/pivotTable.go
index 96e3627..bffda17 100644
--- a/pivotTable.go
+++ b/pivotTable.go
@@ -80,7 +80,7 @@ type PivotTableField struct {
// "fmt"
// "math/rand"
//
-// "github.com/360EntSecGroup-Skylar/excelize"
+// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {