diff --git a/README.md b/README.md index 6afcc7e729..4dbf532c01 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 f54cf01d6f..25b2fbf482 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 577cfaae77..7da24938af 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 6998b778bc..f928797cac 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 22adefd454..4dd28306d7 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 57f7838b2a..32c8d715ae 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 6adfa718af..1a9cac1075 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 96e362783e..bffda17334 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() {