- 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
This commit is contained in:
xuri 2020-05-21 22:57:58 +08:00
parent 98221a332f
commit 2efc7107ff
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
4 changed files with 20 additions and 20 deletions

22
calc.go
View File

@ -56,7 +56,7 @@ type cellRange struct {
// formulaArg is the argument of a formula or function. // formulaArg is the argument of a formula or function.
type formulaArg struct { type formulaArg struct {
Value string Value string
Matrix []string Matrix [][]string
} }
// formulaFuncs is the type of the formula functions. // 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 { for idx, val := range result {
arg := formulaArg{Value: val} arg := formulaArg{Value: val}
if idx < len(matrix) { if idx == 0 {
arg.Matrix = matrix[idx] arg.Matrix = matrix
} }
argsList.PushBack(arg) argsList.PushBack(arg)
} }
@ -1850,17 +1850,13 @@ func det(sqMtx [][]float64) float64 {
// //
func (fn *formulaFuncs) MDETERM(argsList *list.List) (result string, err error) { func (fn *formulaFuncs) MDETERM(argsList *list.List) (result string, err error) {
var num float64 var num float64
var rows int
var numMtx = [][]float64{} var numMtx = [][]float64{}
var strMtx = [][]string{} var strMtx = argsList.Front().Value.(formulaArg).Matrix
for arg := argsList.Front(); arg != nil; arg = arg.Next() { if argsList.Len() < 1 {
if len(arg.Value.(formulaArg).Matrix) == 0 { return
break
} }
strMtx = append(strMtx, arg.Value.(formulaArg).Matrix) var rows = len(strMtx)
rows++ for _, row := range argsList.Front().Value.(formulaArg).Matrix {
}
for _, row := range strMtx {
if len(row) != rows { if len(row) != rows {
err = errors.New(formulaErrorVALUE) err = errors.New(formulaErrorVALUE)
return 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) result = fmt.Sprintf("%g", float64(int(number*adjust))/adjust)
return return
} }
// Statistical functions

View File

@ -28,7 +28,7 @@ import (
"golang.org/x/net/html/charset" "golang.org/x/net/html/charset"
) )
// File define a populated XLSX file struct. // File define a populated spreadsheet file struct.
type File struct { type File struct {
checked map[string]bool checked map[string]bool
sheetMap map[string]string sheetMap map[string]string
@ -52,8 +52,8 @@ type File struct {
type charsetTranscoderFn func(charset string, input io.Reader) (rdr io.Reader, err error) 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 // OpenFile take the name of an spreadsheet file and returns a populated
// struct for it. // spreadsheet file struct for it.
func OpenFile(filename string) (*File, error) { func OpenFile(filename string) (*File, error) {
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { 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) { func OpenReader(r io.Reader) (*File, error) {
b, err := ioutil.ReadAll(r) b, err := ioutil.ReadAll(r)
if err != nil { if err != nil {

8
lib.go
View File

@ -21,7 +21,7 @@ import (
"unsafe" "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. // filesystem.
func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) { func ReadZipReader(r *zip.Reader) (map[string][]byte, int, error) {
fileList := make(map[string][]byte, len(r.File)) fileList := make(map[string][]byte, len(r.File))
@ -160,8 +160,8 @@ func ColumnNumberToName(num int) (string, error) {
// //
// Example: // Example:
// //
// CellCoordinates("A1") // returns 1, 1, nil // excelize.CellNameToCoordinates("A1") // returns 1, 1, nil
// CellCoordinates("Z3") // returns 26, 3, nil // excelize.CellNameToCoordinates("Z3") // returns 26, 3, nil
// //
func CellNameToCoordinates(cell string) (int, int, error) { func CellNameToCoordinates(cell string) (int, int, error) {
const msg = "cannot convert cell %q to coordinates: %v" const msg = "cannot convert cell %q to coordinates: %v"
@ -184,7 +184,7 @@ func CellNameToCoordinates(cell string) (int, int, error) {
// //
// Example: // Example:
// //
// CoordinatesToCellName(1, 1) // returns "A1", nil // excelize.CoordinatesToCellName(1, 1) // returns "A1", nil
// //
func CoordinatesToCellName(col, row int) (string, error) { func CoordinatesToCellName(col, row int) (string, error) {
if col < 1 || row < 1 { if col < 1 || row < 1 {

View File

@ -607,6 +607,7 @@ func (f *File) drawingResize(sheet string, cell string, width, height float64, f
} }
} }
if inMergeCell { if inMergeCell {
cellWidth, cellHeight = 0, 0
c, r = rng[0], rng[1] c, r = rng[0], rng[1]
for col := rng[0] - 1; col < rng[2]; col++ { for col := rng[0] - 1; col < rng[2]; col++ {
cellWidth += f.getColWidth(sheet, col) cellWidth += f.getColWidth(sheet, col)