Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new formula func CLEAN and TRIM, change import path to v2 #747

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ package main
import (
"fmt"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down Expand Up @@ -68,7 +68,7 @@ package main
import (
"fmt"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down Expand Up @@ -107,7 +107,7 @@ package main
import (
"fmt"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down Expand Up @@ -142,7 +142,7 @@ import (
_ "image/jpeg"
_ "image/png"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down
8 changes: 4 additions & 4 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ package main
import (
"fmt"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down Expand Up @@ -68,7 +68,7 @@ package main
import (
"fmt"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down Expand Up @@ -107,7 +107,7 @@ package main
import (
"fmt"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down Expand Up @@ -142,7 +142,7 @@ import (
_ "image/jpeg"
_ "image/png"

"github.com/360EntSecGroup-Skylar/excelize"
"github.com/360EntSecGroup-Skylar/excelize/v2"
)

func main() {
Expand Down
29 changes: 29 additions & 0 deletions calc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 14 additions & 0 deletions calc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions picture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pivotTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ type PivotTableField struct {
// "fmt"
// "math/rand"
//
// "github.com/360EntSecGroup-Skylar/excelize"
// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {
Expand Down