Skip to content

Commit 2af96c0

Browse files
committed
qax-os#65 fn: N, PERCENTILE.INC and T
typo fixed
1 parent 6d7bd7c commit 2af96c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+177
-96
lines changed

adjust.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

calc.go

+59-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.
@@ -323,6 +323,7 @@ var tokenPriority = map[string]int{
323323
// MROUND
324324
// MULTINOMIAL
325325
// MUNIT
326+
// N
326327
// NA
327328
// NORM.DIST
328329
// NORMDIST
@@ -339,6 +340,7 @@ var tokenPriority = map[string]int{
339340
// OCT2HEX
340341
// ODD
341342
// OR
343+
// PERCENTILE.INC
342344
// PERCENTILE
343345
// PERMUT
344346
// PERMUTATIONA
@@ -380,6 +382,7 @@ var tokenPriority = map[string]int{
380382
// SUM
381383
// SUMIF
382384
// SUMSQ
385+
// T
383386
// TAN
384387
// TANH
385388
// TODAY
@@ -4521,6 +4524,19 @@ func (fn *formulaFuncs) min(mina bool, argsList *list.List) formulaArg {
45214524
return newNumberFormulaArg(min)
45224525
}
45234526

4527+
// PERCENTILEdotINC function returns the k'th percentile (i.e. the value below
4528+
// which k% of the data values fall) for a supplied range of values and a
4529+
// supplied k. The syntax of the function is:
4530+
//
4531+
// PERCENTILE.INC(array,k)
4532+
//
4533+
func (fn *formulaFuncs) PERCENTILEdotINC(argsList *list.List) formulaArg {
4534+
if argsList.Len() != 2 {
4535+
return newErrorFormulaArg(formulaErrorVALUE, "PERCENTILE.INC requires 2 arguments")
4536+
}
4537+
return fn.PERCENTILE(argsList)
4538+
}
4539+
45244540
// PERCENTILE function returns the k'th percentile (i.e. the value below which
45254541
// k% of the data values fall) for a supplied range of values and a supplied
45264542
// k. The syntax of the function is:
@@ -4858,6 +4874,28 @@ func (fn *formulaFuncs) ISTEXT(argsList *list.List) formulaArg {
48584874
return newBoolFormulaArg(token.Type == ArgString)
48594875
}
48604876

4877+
// N function converts data into a numeric value. The syntax of the function
4878+
// is:
4879+
//
4880+
// N(value)
4881+
//
4882+
func (fn *formulaFuncs) N(argsList *list.List) formulaArg {
4883+
if argsList.Len() != 1 {
4884+
return newErrorFormulaArg(formulaErrorVALUE, "N requires 1 argument")
4885+
}
4886+
token, num := argsList.Front().Value.(formulaArg), 0.0
4887+
if token.Type == ArgError {
4888+
return token
4889+
}
4890+
if arg := token.ToNumber(); arg.Type == ArgNumber {
4891+
num = arg.Number
4892+
}
4893+
if token.Value() == "TRUE" {
4894+
num = 1
4895+
}
4896+
return newNumberFormulaArg(num)
4897+
}
4898+
48614899
// NA function returns the Excel #N/A error. This error message has the
48624900
// meaning 'value not available' and is produced when an Excel Formula is
48634901
// unable to find a value that it needs. The syntax of the function is:
@@ -4883,6 +4921,26 @@ func (fn *formulaFuncs) SHEET(argsList *list.List) formulaArg {
48834921
return newNumberFormulaArg(float64(fn.f.GetSheetIndex(fn.sheet) + 1))
48844922
}
48854923

4924+
// T function tests if a supplied value is text and if so, returns the
4925+
// supplied text; Otherwise, the function returns an empty text string. The
4926+
// syntax of the function is:
4927+
//
4928+
// T(value)
4929+
//
4930+
func (fn *formulaFuncs) T(argsList *list.List) formulaArg {
4931+
if argsList.Len() != 1 {
4932+
return newErrorFormulaArg(formulaErrorVALUE, "T requires 1 argument")
4933+
}
4934+
token := argsList.Front().Value.(formulaArg)
4935+
if token.Type == ArgError {
4936+
return token
4937+
}
4938+
if token.Type == ArgNumber {
4939+
return newStringFormulaArg("")
4940+
}
4941+
return newStringFormulaArg(token.Value())
4942+
}
4943+
48864944
// Logical Functions
48874945

48884946
// AND function tests a number of supplied conditions and returns TRUE or

calc_test.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,8 @@ func TestCalcCellValue(t *testing.T) {
680680
"=MINA(MUNIT(2))": "0",
681681
"=MINA(INT(1))": "1",
682682
"=MINA(A1:B4,MUNIT(1),INT(0),1,E1:F2,\"\")": "0",
683+
// PERCENTILE.INC
684+
"=PERCENTILE.INC(A1:A4,0.2)": "0.6",
683685
// PERCENTILE
684686
"=PERCENTILE(A1:A4,0.2)": "0.6",
685687
"=PERCENTILE(0,0)": "0",
@@ -730,8 +732,17 @@ func TestCalcCellValue(t *testing.T) {
730732
// ISTEXT
731733
"=ISTEXT(D1)": "TRUE",
732734
"=ISTEXT(A1)": "FALSE",
735+
// N
736+
"=N(10)": "10",
737+
"=N(\"10\")": "10",
738+
"=N(\"x\")": "0",
739+
"=N(TRUE)": "1",
740+
"=N(FALSE)": "0",
733741
// SHEET
734-
"SHEET()": "1",
742+
"=SHEET()": "1",
743+
// T
744+
"=T(\"text\")": "text",
745+
"=T(N(10))": "",
735746
// Logical Functions
736747
// AND
737748
"=AND(0)": "FALSE",
@@ -1479,6 +1490,8 @@ func TestCalcCellValue(t *testing.T) {
14791490
// MINA
14801491
"=MINA()": "MINA requires at least 1 argument",
14811492
"=MINA(NA())": "#N/A",
1493+
// PERCENTILE.INC
1494+
"=PERCENTILE.INC()": "PERCENTILE.INC requires 2 arguments",
14821495
// PERCENTILE
14831496
"=PERCENTILE()": "PERCENTILE requires 2 arguments",
14841497
"=PERCENTILE(0,\"\")": "strconv.ParseFloat: parsing \"\": invalid syntax",
@@ -1525,11 +1538,17 @@ func TestCalcCellValue(t *testing.T) {
15251538
`=ISODD("text")`: "strconv.Atoi: parsing \"text\": invalid syntax",
15261539
// ISTEXT
15271540
"=ISTEXT()": "ISTEXT requires 1 argument",
1541+
// N
1542+
"=N()": "N requires 1 argument",
1543+
"=N(NA())": "#N/A",
15281544
// NA
15291545
"=NA()": "#N/A",
15301546
"=NA(1)": "NA accepts no arguments",
15311547
// SHEET
15321548
"=SHEET(1)": "SHEET accepts no arguments",
1549+
// T
1550+
"=T()": "T requires 1 argument",
1551+
"=T(NA())": "#N/A",
15331552
// Logical Functions
15341553
// AND
15351554
`=AND("text")`: "strconv.ParseFloat: parsing \"text\": invalid syntax",

calcchain.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

cell.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

chart.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

col.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

comment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

comment_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//

crypt_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//

datavalidation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

datavalidation_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//

date.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

docProps.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

docProps_test.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
6-
// and read from XLSX files. Support reads and writes XLSX file generated by
7-
// Microsoft Excel™ 2007 and later. Support save file without losing original
8-
// charts of XLSX. This library needs Go version 1.10 or later.
6+
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
8+
// complex components by high compatibility, and provided streaming API for
9+
// generating or reading data from a worksheet with huge amounts of data. This
10+
// library needs Go version 1.10 or later.
911

1012
package excelize
1113

@@ -43,7 +45,7 @@ func TestSetDocProps(t *testing.T) {
4345
f.XLSX["docProps/core.xml"] = nil
4446
assert.NoError(t, f.SetDocProps(&DocProperties{}))
4547

46-
// Test unsupport charset
48+
// Test unsupported charset
4749
f = NewFile()
4850
f.XLSX["docProps/core.xml"] = MacintoshCyrillicCharset
4951
assert.EqualError(t, f.SetDocProps(&DocProperties{}), "xml decode error: XML syntax error on line 1: invalid UTF-8")
@@ -61,7 +63,7 @@ func TestGetDocProps(t *testing.T) {
6163
_, err = f.GetDocProps()
6264
assert.NoError(t, err)
6365

64-
// Test unsupport charset
66+
// Test unsupported charset
6567
f = NewFile()
6668
f.XLSX["docProps/core.xml"] = MacintoshCyrillicCharset
6769
_, err = f.GetDocProps()

drawing.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

drawing_test.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
6-
// and read from XLSX files. Support reads and writes XLSX file generated by
7-
// Microsoft Excel™ 2007 and later. Support save file without losing original
8-
// charts of XLSX. This library needs Go version 1.10 or later.
6+
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
8+
// complex components by high compatibility, and provided streaming API for
9+
// generating or reading data from a worksheet with huge amounts of data. This
10+
// library needs Go version 1.10 or later.
911

1012
package excelize
1113

@@ -22,6 +24,6 @@ func TestDrawingParser(t *testing.T) {
2224
}
2325
// Test with one cell anchor
2426
f.drawingParser("wsDr")
25-
// Test with unsupport charset
27+
// Test with unsupported charset
2628
f.drawingParser("charset")
2729
}

errors.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44
//
55
// Package excelize providing a set of functions that allow you to write to
66
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
7-
// spreadsheet documents generated by Microsoft Exce™ 2007 and later. Supports
7+
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
88
// complex components by high compatibility, and provided streaming API for
99
// generating or reading data from a worksheet with huge amounts of data. This
1010
// library needs Go version 1.10 or later.

excelize.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
1+
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
22
// this source code is governed by a BSD-style license that can be found in
33
// the LICENSE file.
44

0 commit comments

Comments
 (0)