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

This commit is contained in:
Zhang Zhipeng 2020-12-14 09:56:42 +08:00 committed by GitHub
parent 61057c58d3
commit ad79505173
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 57 additions and 14 deletions

View File

@ -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() {

View File

@ -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() {

29
calc.go
View File

@ -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
}

View File

@ -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()

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -80,7 +80,7 @@ type PivotTableField struct {
// "fmt"
// "math/rand"
//
// "github.com/360EntSecGroup-Skylar/excelize"
// "github.com/360EntSecGroup-Skylar/excelize/v2"
// )
//
// func main() {