Просмотр исходного кода

- 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

xuri 5 лет назад
Родитель
Сommit
2efc7107ff
4 измененных файлов с 20 добавлено и 20 удалено
  1. 10 12
      calc.go
  2. 5 4
      excelize.go
  3. 4 4
      lib.go
  4. 1 0
      picture.go

+ 10 - 12
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

+ 5 - 4
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 {

+ 4 - 4
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 {

+ 1 - 0
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)