Skip to content

Commit ad79505

Browse files
authored
new formula func CLEAN and TRIM, change import path to v2 (qax-os#747)
1 parent 61057c5 commit ad79505

File tree

8 files changed

+57
-14
lines changed

8 files changed

+57
-14
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ package main
3939
import (
4040
"fmt"
4141

42-
"github.com/360EntSecGroup-Skylar/excelize"
42+
"github.com/360EntSecGroup-Skylar/excelize/v2"
4343
)
4444

4545
func main() {
@@ -68,7 +68,7 @@ package main
6868
import (
6969
"fmt"
7070

71-
"github.com/360EntSecGroup-Skylar/excelize"
71+
"github.com/360EntSecGroup-Skylar/excelize/v2"
7272
)
7373

7474
func main() {
@@ -107,7 +107,7 @@ package main
107107
import (
108108
"fmt"
109109

110-
"github.com/360EntSecGroup-Skylar/excelize"
110+
"github.com/360EntSecGroup-Skylar/excelize/v2"
111111
)
112112

113113
func main() {
@@ -142,7 +142,7 @@ import (
142142
_ "image/jpeg"
143143
_ "image/png"
144144

145-
"github.com/360EntSecGroup-Skylar/excelize"
145+
"github.com/360EntSecGroup-Skylar/excelize/v2"
146146
)
147147

148148
func main() {

README_zh.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ package main
3939
import (
4040
"fmt"
4141

42-
"github.com/360EntSecGroup-Skylar/excelize"
42+
"github.com/360EntSecGroup-Skylar/excelize/v2"
4343
)
4444

4545
func main() {
@@ -68,7 +68,7 @@ package main
6868
import (
6969
"fmt"
7070

71-
"github.com/360EntSecGroup-Skylar/excelize"
71+
"github.com/360EntSecGroup-Skylar/excelize/v2"
7272
)
7373

7474
func main() {
@@ -107,7 +107,7 @@ package main
107107
import (
108108
"fmt"
109109

110-
"github.com/360EntSecGroup-Skylar/excelize"
110+
"github.com/360EntSecGroup-Skylar/excelize/v2"
111111
)
112112

113113
func main() {
@@ -142,7 +142,7 @@ import (
142142
_ "image/jpeg"
143143
_ "image/png"
144144

145-
"github.com/360EntSecGroup-Skylar/excelize"
145+
"github.com/360EntSecGroup-Skylar/excelize/v2"
146146
)
147147

148148
func main() {

calc.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,3 +3365,32 @@ func makeDate(y int, m time.Month, d int) int64 {
33653365
func daysBetween(startDate, endDate int64) float64 {
33663366
return float64(int(0.5 + float64((endDate-startDate)/86400)))
33673367
}
3368+
3369+
// Text Functions
3370+
3371+
// CLEAN removes all non-printable characters from a supplied text string.
3372+
func (fn *formulaFuncs) CLEAN(argsList *list.List) (result string, err error) {
3373+
if argsList.Len() != 1 {
3374+
err = errors.New("CLEAN requires 1 argument")
3375+
return
3376+
}
3377+
b := bytes.Buffer{}
3378+
for _, c := range argsList.Front().Value.(formulaArg).String {
3379+
if c > 31 {
3380+
b.WriteRune(c)
3381+
}
3382+
}
3383+
result = b.String()
3384+
return
3385+
}
3386+
3387+
// TRIM removes extra spaces (i.e. all spaces except for single spaces between
3388+
// words or characters) from a supplied text string.
3389+
func (fn *formulaFuncs) TRIM(argsList *list.List) (result string, err error) {
3390+
if argsList.Len() != 1 {
3391+
err = errors.New("TRIM requires 1 argument")
3392+
return
3393+
}
3394+
result = strings.TrimSpace(argsList.Front().Value.(formulaArg).String)
3395+
return
3396+
}

calc_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,13 @@ func TestCalcCellValue(t *testing.T) {
463463
// DATE
464464
"=DATE(2020,10,21)": "2020-10-21 00:00:00 +0000 UTC",
465465
"=DATE(1900,1,1)": "1899-12-31 00:00:00 +0000 UTC",
466+
// Text Functions
467+
// CLEAN
468+
"=CLEAN(\"\u0009clean text\")": "clean text",
469+
"=CLEAN(0)": "0",
470+
// TRIM
471+
"=TRIM(\" trim text \")": "trim text",
472+
"=TRIM(0)": "0",
466473
}
467474
for formula, expected := range mathCalc {
468475
f := prepareData()
@@ -779,6 +786,13 @@ func TestCalcCellValue(t *testing.T) {
779786
`=DATE("text",10,21)`: "DATE requires 3 number arguments",
780787
`=DATE(2020,"text",21)`: "DATE requires 3 number arguments",
781788
`=DATE(2020,10,"text")`: "DATE requires 3 number arguments",
789+
// Text Functions
790+
// CLEAN
791+
"=CLEAN()": "CLEAN requires 1 argument",
792+
"=CLEAN(1,2)": "CLEAN requires 1 argument",
793+
// TRIM
794+
"=TRIM()": "TRIM requires 1 argument",
795+
"=TRIM(1,2)": "TRIM requires 1 argument",
782796
}
783797
for formula, expected := range mathCalcError {
784798
f := prepareData()

cell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ func (f *File) SetCellHyperLink(sheet, axis, link, linkType string) error {
502502
// import (
503503
// "fmt"
504504
//
505-
// "github.com/360EntSecGroup-Skylar/excelize"
505+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
506506
// )
507507
//
508508
// func main() {

chart.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
510510
// import (
511511
// "fmt"
512512
//
513-
// "github.com/360EntSecGroup-Skylar/excelize"
513+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
514514
// )
515515
//
516516
// func main() {
@@ -708,7 +708,7 @@ func parseFormatChartSet(formatSet string) (*formatChart, error) {
708708
// import (
709709
// "fmt"
710710
//
711-
// "github.com/360EntSecGroup-Skylar/excelize"
711+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
712712
// )
713713
//
714714
// func main() {

picture.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func parseFormatPictureSet(formatSet string) (*formatPicture, error) {
5555
// _ "image/jpeg"
5656
// _ "image/png"
5757
//
58-
// "github.com/360EntSecGroup-Skylar/excelize"
58+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
5959
// )
6060
//
6161
// func main() {
@@ -111,7 +111,7 @@ func (f *File) AddPicture(sheet, cell, picture, format string) error {
111111
// _ "image/jpeg"
112112
// "io/ioutil"
113113
//
114-
// "github.com/360EntSecGroup-Skylar/excelize"
114+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
115115
// )
116116
//
117117
// func main() {

pivotTable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type PivotTableField struct {
8080
// "fmt"
8181
// "math/rand"
8282
//
83-
// "github.com/360EntSecGroup-Skylar/excelize"
83+
// "github.com/360EntSecGroup-Skylar/excelize/v2"
8484
// )
8585
//
8686
// func main() {

0 commit comments

Comments
 (0)