Skip to content

Commit 2efc710

Browse files
committed
- 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
1 parent 98221a3 commit 2efc710

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

calc.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type cellRange struct {
5656
// formulaArg is the argument of a formula or function.
5757
type formulaArg struct {
5858
Value string
59-
Matrix []string
59+
Matrix [][]string
6060
}
6161

6262
// formulaFuncs is the type of the formula functions.
@@ -172,8 +172,8 @@ func (f *File) evalInfixExp(sheet string, tokens []efp.Token) (efp.Token, error)
172172
}
173173
for idx, val := range result {
174174
arg := formulaArg{Value: val}
175-
if idx < len(matrix) {
176-
arg.Matrix = matrix[idx]
175+
if idx == 0 {
176+
arg.Matrix = matrix
177177
}
178178
argsList.PushBack(arg)
179179
}
@@ -1850,17 +1850,13 @@ func det(sqMtx [][]float64) float64 {
18501850
//
18511851
func (fn *formulaFuncs) MDETERM(argsList *list.List) (result string, err error) {
18521852
var num float64
1853-
var rows int
18541853
var numMtx = [][]float64{}
1855-
var strMtx = [][]string{}
1856-
for arg := argsList.Front(); arg != nil; arg = arg.Next() {
1857-
if len(arg.Value.(formulaArg).Matrix) == 0 {
1858-
break
1859-
}
1860-
strMtx = append(strMtx, arg.Value.(formulaArg).Matrix)
1861-
rows++
1854+
var strMtx = argsList.Front().Value.(formulaArg).Matrix
1855+
if argsList.Len() < 1 {
1856+
return
18621857
}
1863-
for _, row := range strMtx {
1858+
var rows = len(strMtx)
1859+
for _, row := range argsList.Front().Value.(formulaArg).Matrix {
18641860
if len(row) != rows {
18651861
err = errors.New(formulaErrorVALUE)
18661862
return
@@ -2630,3 +2626,5 @@ func (fn *formulaFuncs) TRUNC(argsList *list.List) (result string, err error) {
26302626
result = fmt.Sprintf("%g", float64(int(number*adjust))/adjust)
26312627
return
26322628
}
2629+
2630+
// Statistical functions

excelize.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"golang.org/x/net/html/charset"
2929
)
3030

31-
// File define a populated XLSX file struct.
31+
// File define a populated spreadsheet file struct.
3232
type File struct {
3333
checked map[string]bool
3434
sheetMap map[string]string
@@ -52,8 +52,8 @@ type File struct {
5252

5353
type charsetTranscoderFn func(charset string, input io.Reader) (rdr io.Reader, err error)
5454

55-
// OpenFile take the name of an XLSX file and returns a populated XLSX file
56-
// struct for it.
55+
// OpenFile take the name of an spreadsheet file and returns a populated
56+
// spreadsheet file struct for it.
5757
func OpenFile(filename string) (*File, error) {
5858
file, err := os.Open(filename)
5959
if err != nil {
@@ -83,7 +83,8 @@ func newFile() *File {
8383
}
8484
}
8585

86-
// OpenReader take an io.Reader and return a populated XLSX file.
86+
// OpenReader read data stream from io.Reader and return a populated
87+
// spreadsheet file.
8788
func OpenReader(r io.Reader) (*File, error) {
8889
b, err := ioutil.ReadAll(r)
8990
if err != nil {

lib.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"unsafe"
2222
)
2323

24-
// ReadZipReader can be used to read an XLSX in memory without touching the
24+
// ReadZipReader can be used to read the spreadsheet in memory without touching the
2525
// filesystem.
2626
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
2727
fileList := make(map[string][]byte, len(r.File))
@@ -160,8 +160,8 @@ func ColumnNumberToName(num int) (string, error) {
160160
//
161161
// Example:
162162
//
163-
// CellCoordinates("A1") // returns 1, 1, nil
164-
// CellCoordinates("Z3") // returns 26, 3, nil
163+
// excelize.CellNameToCoordinates("A1") // returns 1, 1, nil
164+
// excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil
165165
//
166166
func CellNameToCoordinates(cell string) (int, int, error) {
167167
const msg = "cannot convert cell %q to coordinates: %v"
@@ -184,7 +184,7 @@ func CellNameToCoordinates(cell string) (int, int, error) {
184184
//
185185
// Example:
186186
//
187-
// CoordinatesToCellName(1, 1) // returns "A1", nil
187+
// excelize.CoordinatesToCellName(1, 1) // returns "A1", nil
188188
//
189189
func CoordinatesToCellName(col, row int) (string, error) {
190190
if col < 1 || row < 1 {

picture.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ func (f *File) drawingResize(sheet string, cell string, width, height float64, f
607607
}
608608
}
609609
if inMergeCell {
610+
cellWidth, cellHeight = 0, 0
610611
c, r = rng[0], rng[1]
611612
for col := rng[0] - 1; col < rng[2]; col++ {
612613
cellWidth += f.getColWidth(sheet, col)

0 commit comments

Comments
 (0)