summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxuri <xuri.me@gmail.com>2020-05-21 22:57:58 +0800
committerxuri <xuri.me@gmail.com>2020-05-21 22:57:58 +0800
commit2efc7107ff30dc7f1e1a798082616ee488f99489 (patch)
tree80ea9e1e9f9246369685acabd0e5dac8271e7d97
parent98221a332ff9c37c9b20c44e9efdbe4c22a5cf5c (diff)
- transform the range to the matrix on the first arg of the formula
- typo fix - reset cell with and height when insert picture into merged cell with autofit
-rw-r--r--calc.go22
-rw-r--r--excelize.go9
-rw-r--r--lib.go8
-rw-r--r--picture.go1
4 files changed, 20 insertions, 20 deletions
diff --git a/calc.go b/calc.go
index 61b6dac..bff7866 100644
--- a/calc.go
+++ b/calc.go
@@ -56,7 +56,7 @@ type cellRange struct {
// formulaArg is the argument of a formula or function.
type formulaArg struct {
Value string
- Matrix []string
+ Matrix [][]string
}
// formulaFuncs is the type of the formula functions.
@@ -172,8 +172,8 @@ func (f *File) evalInfixExp(sheet string, tokens []efp.Token) (efp.Token, error)
}
for idx, val := range result {
arg := formulaArg{Value: val}
- if idx < len(matrix) {
- arg.Matrix = matrix[idx]
+ if idx == 0 {
+ arg.Matrix = matrix
}
argsList.PushBack(arg)
}
@@ -1850,17 +1850,13 @@ func det(sqMtx [][]float64) float64 {
//
func (fn *formulaFuncs) MDETERM(argsList *list.List) (result string, err error) {
var num float64
- var rows int
var numMtx = [][]float64{}
- var strMtx = [][]string{}
- for arg := argsList.Front(); arg != nil; arg = arg.Next() {
- if len(arg.Value.(formulaArg).Matrix) == 0 {
- break
- }
- strMtx = append(strMtx, arg.Value.(formulaArg).Matrix)
- rows++
+ var strMtx = argsList.Front().Value.(formulaArg).Matrix
+ if argsList.Len() < 1 {
+ return
}
- for _, row := range strMtx {
+ var rows = len(strMtx)
+ for _, row := range argsList.Front().Value.(formulaArg).Matrix {
if len(row) != rows {
err = errors.New(formulaErrorVALUE)
return
@@ -2630,3 +2626,5 @@ func (fn *formulaFuncs) TRUNC(argsList *list.List) (result string, err error) {
result = fmt.Sprintf("%g", float64(int(number*adjust))/adjust)
return
}
+
+// Statistical functions
diff --git a/excelize.go b/excelize.go
index 04e2e85..3fd25aa 100644
--- a/excelize.go
+++ b/excelize.go
@@ -28,7 +28,7 @@ import (
"golang.org/x/net/html/charset"
)
-// File define a populated XLSX file struct.
+// File define a populated spreadsheet file struct.
type File struct {
checked map[string]bool
sheetMap map[string]string
@@ -52,8 +52,8 @@ type File struct {
type charsetTranscoderFn func(charset string, input io.Reader) (rdr io.Reader, err error)
-// OpenFile take the name of an XLSX file and returns a populated XLSX file
-// struct for it.
+// OpenFile take the name of an spreadsheet file and returns a populated
+// spreadsheet file struct for it.
func OpenFile(filename string) (*File, error) {
file, err := os.Open(filename)
if err != nil {
@@ -83,7 +83,8 @@ func newFile() *File {
}
}
-// OpenReader take an io.Reader and return a populated XLSX file.
+// OpenReader read data stream from io.Reader and return a populated
+// spreadsheet file.
func OpenReader(r io.Reader) (*File, error) {
b, err := ioutil.ReadAll(r)
if err != nil {
diff --git a/lib.go b/lib.go
index 79c7cd4..41b03c7 100644
--- a/lib.go
+++ b/lib.go
@@ -21,7 +21,7 @@ import (
"unsafe"
)
-// ReadZipReader can be used to read an XLSX in memory without touching the
+// ReadZipReader can be used to read the spreadsheet in memory without touching the
// filesystem.
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
fileList := make(map[string][]byte, len(r.File))
@@ -160,8 +160,8 @@ func ColumnNumberToName(num int) (string, error) {
//
// Example:
//
-// CellCoordinates("A1") // returns 1, 1, nil
-// CellCoordinates("Z3") // returns 26, 3, nil
+// excelize.CellNameToCoordinates("A1") // returns 1, 1, nil
+// excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil
//
func CellNameToCoordinates(cell string) (int, int, error) {
const msg = "cannot convert cell %q to coordinates: %v"
@@ -184,7 +184,7 @@ func CellNameToCoordinates(cell string) (int, int, error) {
//
// Example:
//
-// CoordinatesToCellName(1, 1) // returns "A1", nil
+// excelize.CoordinatesToCellName(1, 1) // returns "A1", nil
//
func CoordinatesToCellName(col, row int) (string, error) {
if col < 1 || row < 1 {
diff --git a/picture.go b/picture.go
index 71c3b8e..cac1af2 100644
--- a/picture.go
+++ b/picture.go
@@ -607,6 +607,7 @@ func (f *File) drawingResize(sheet string, cell string, width, height float64, f
}
}
if inMergeCell {
+ cellWidth, cellHeight = 0, 0
c, r = rng[0], rng[1]
for col := rng[0] - 1; col < rng[2]; col++ {
cellWidth += f.getColWidth(sheet, col)