diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2743d60..c56feda 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -5,7 +5,7 @@ jobs: test: strategy: matrix: - go-version: [1.18.x, 1.19.x, 1.20.x, '>=1.21.1'] + go-version: [1.18.x, 1.19.x, 1.20.x, '>=1.21.1', 1.22.x] os: [ubuntu-latest, macos-latest, windows-latest] targetplatform: [x86, x64] @@ -17,6 +17,7 @@ jobs: uses: actions/setup-go@v5 with: go-version: ${{ matrix.go-version }} + cache: false - name: Checkout code uses: actions/checkout@v4 diff --git a/calc.go b/calc.go index f03c573..496ecd4 100644 --- a/calc.go +++ b/calc.go @@ -281,6 +281,10 @@ func (fa formulaArg) Value() (value string) { return fmt.Sprintf("%g", fa.Number) case ArgString: return fa.String + case ArgMatrix: + if args := fa.ToList(); len(args) > 0 { + return args[0].Value() + } case ArgError: return fa.Error } @@ -299,6 +303,10 @@ func (fa formulaArg) ToNumber() formulaArg { } case ArgNumber: n = fa.Number + case ArgMatrix: + if args := fa.ToList(); len(args) > 0 { + return args[0].ToNumber() + } } return newNumberFormulaArg(n) } @@ -920,9 +928,14 @@ func newEmptyFormulaArg() formulaArg { // // TODO: handle subtypes: Nothing, Text, Logical, Error, Concatenation, Intersection, Union func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.Token) (formulaArg, error) { - var err error - opdStack, optStack, opfStack, opfdStack, opftStack, argsStack := NewStack(), NewStack(), NewStack(), NewStack(), NewStack(), NewStack() - var inArray, inArrayRow bool + var ( + err error + inArray, inArrayRow bool + formulaArray [][]formulaArg + formulaArrayRow []formulaArg + opdStack, optStack, opfStack = NewStack(), NewStack(), NewStack() + opfdStack, opftStack, argsStack = NewStack(), NewStack(), NewStack() + ) for i := 0; i < len(tokens); i++ { token := tokens[i] @@ -936,11 +949,11 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T // function start if isFunctionStartToken(token) { if token.TValue == "ARRAY" { - inArray = true + inArray, formulaArray = true, [][]formulaArg{} continue } if token.TValue == "ARRAYROW" { - inArrayRow = true + inArrayRow, formulaArrayRow = true, []formulaArg{} continue } opfStack.Push(token) @@ -1021,14 +1034,16 @@ func (f *File) evalInfixExp(ctx *calcContext, sheet, cell string, tokens []efp.T } if inArrayRow && isOperand(token) { + formulaArrayRow = append(formulaArrayRow, opfdStack.Pop().(formulaArg)) continue } if inArrayRow && isFunctionStopToken(token) { + formulaArray = append(formulaArray, formulaArrayRow) inArrayRow = false continue } if inArray && isFunctionStopToken(token) { - argsStack.Peek().(*list.List).PushBack(opfdStack.Pop()) + argsStack.Peek().(*list.List).PushBack(newMatrixFormulaArg(formulaArray)) inArray = false continue } @@ -1825,13 +1840,13 @@ func (fn *formulaFuncs) bassel(argsList *list.List, modfied bool) formulaArg { if n.Type != ArgNumber { return n } - max, x1 := 100, x.Number*0.5 + maxVal, x1 := 100, x.Number*0.5 x2 := x1 * x1 x1 = math.Pow(x1, n.Number) n1, n2, n3, n4, add := fact(n.Number), 1.0, 0.0, n.Number, false result := x1 / n1 t := result * 0.9 - for result != t && max != 0 { + for result != t && maxVal != 0 { x1 *= x2 n3++ n1 *= n3 @@ -1844,7 +1859,7 @@ func (fn *formulaFuncs) bassel(argsList *list.List, modfied bool) formulaArg { } else { result -= r } - max-- + maxVal-- add = !add } return newNumberFormulaArg(result) @@ -2151,8 +2166,8 @@ func (fn *formulaFuncs) bitwise(name string, argsList *list.List) formulaArg { if num1.Type != ArgNumber || num2.Type != ArgNumber { return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM) } - max := math.Pow(2, 48) - 1 - if num1.Number < 0 || num1.Number > max || num2.Number < 0 || num2.Number > max { + maxVal := math.Pow(2, 48) - 1 + if num1.Number < 0 || num1.Number > maxVal || num2.Number < 0 || num2.Number > maxVal { return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM) } bitwiseFuncMap := map[string]func(a, b int) int{ @@ -6958,9 +6973,9 @@ func (fn *formulaFuncs) BETAdotINV(argsList *list.List) formulaArg { // incompleteGamma is an implementation of the incomplete gamma function. func incompleteGamma(a, x float64) float64 { - max := 32 + maxVal := 32 summer := 0.0 - for n := 0; n <= max; n++ { + for n := 0; n <= maxVal; n++ { divisor := a for i := 1; i <= n; i++ { divisor *= a + float64(i) @@ -7079,7 +7094,7 @@ func (fn *formulaFuncs) BINOMdotDISTdotRANGE(argsList *list.List) formulaArg { // binominv implement inverse of the binomial distribution calculation. func binominv(n, p, alpha float64) float64 { - q, i, sum, max := 1-p, 0.0, 0.0, 0.0 + q, i, sum, maxVal := 1-p, 0.0, 0.0, 0.0 n = math.Floor(n) if q > p { factor := math.Pow(q, n) @@ -7091,8 +7106,8 @@ func binominv(n, p, alpha float64) float64 { return i } factor := math.Pow(p, n) - sum, max = 1-factor, n - for i = 0; i < max && sum >= alpha; i++ { + sum, maxVal = 1-factor, n + for i = 0; i < maxVal && sum >= alpha; i++ { factor *= (n - i) / (i + 1) * q / p sum -= factor } @@ -8078,10 +8093,13 @@ func (fn *formulaFuncs) FORECASTdotLINEAR(argsList *list.List) formulaArg { return fn.pearsonProduct("FORECAST.LINEAR", 3, argsList) } -// maritxToSortedColumnList convert matrix formula arguments to a ascending +// matrixToSortedColumnList convert matrix formula arguments to a ascending // order list by column. -func maritxToSortedColumnList(arg formulaArg) formulaArg { - mtx, cols := []formulaArg{}, len(arg.Matrix[0]) +func matrixToSortedColumnList(arg formulaArg) formulaArg { + var ( + mtx []formulaArg + cols = len(arg.Matrix[0]) + ) for colIdx := 0; colIdx < cols; colIdx++ { for _, row := range arg.Matrix { cell := row[colIdx] @@ -8120,14 +8138,14 @@ func (fn *formulaFuncs) FREQUENCY(argsList *list.List) formulaArg { c [][]formulaArg i, j int ) - if dataMtx = maritxToSortedColumnList(data); dataMtx.Type != ArgList { + if dataMtx = matrixToSortedColumnList(data); dataMtx.Type != ArgList { return dataMtx } - if binsMtx = maritxToSortedColumnList(bins); binsMtx.Type != ArgList { + if binsMtx = matrixToSortedColumnList(bins); binsMtx.Type != ArgList { return binsMtx } for row := 0; row < len(binsMtx.List)+1; row++ { - rows := []formulaArg{} + var rows []formulaArg for col := 0; col < 1; col++ { rows = append(rows, newNumberFormulaArg(0)) } @@ -8349,8 +8367,8 @@ func (fn *formulaFuncs) GEOMEAN(argsList *list.List) formulaArg { return product } count := fn.COUNT(argsList) - min := fn.MIN(argsList) - if product.Number > 0 && min.Number > 0 { + minVal := fn.MIN(argsList) + if product.Number > 0 && minVal.Number > 0 { return newNumberFormulaArg(math.Pow(product.Number, 1/count.Number)) } return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM) @@ -9055,7 +9073,7 @@ func (fn *formulaFuncs) HARMEAN(argsList *list.List) formulaArg { if argsList.Len() < 1 { return newErrorFormulaArg(formulaErrorVALUE, "HARMEAN requires at least 1 argument") } - if min := fn.MIN(argsList); min.Number < 0 { + if minVal := fn.MIN(argsList); minVal.Number < 0 { return newErrorFormulaArg(formulaErrorNA, formulaErrorNA) } number, val, cnt := 0.0, 0.0, 0.0 @@ -10002,7 +10020,7 @@ func (fn *formulaFuncs) MAX(argsList *list.List) formulaArg { if argsList.Len() == 0 { return newErrorFormulaArg(formulaErrorVALUE, "MAX requires at least 1 argument") } - return fn.max(false, argsList) + return fn.maxValue(false, argsList) } // MAXA function returns the largest value from a supplied set of numeric @@ -10015,7 +10033,7 @@ func (fn *formulaFuncs) MAXA(argsList *list.List) formulaArg { if argsList.Len() == 0 { return newErrorFormulaArg(formulaErrorVALUE, "MAXA requires at least 1 argument") } - return fn.max(true, argsList) + return fn.maxValue(true, argsList) } // MAXIFS function returns the maximum value from a subset of values that are @@ -10031,36 +10049,36 @@ func (fn *formulaFuncs) MAXIFS(argsList *list.List) formulaArg { return newErrorFormulaArg(formulaErrorNA, formulaErrorNA) } var args []formulaArg - max, maxRange := -math.MaxFloat64, argsList.Front().Value.(formulaArg).Matrix + maxVal, maxRange := -math.MaxFloat64, argsList.Front().Value.(formulaArg).Matrix for arg := argsList.Front().Next(); arg != nil; arg = arg.Next() { args = append(args, arg.Value.(formulaArg)) } for _, ref := range formulaIfsMatch(args) { - if num := maxRange[ref.Row][ref.Col].ToNumber(); num.Type == ArgNumber && max < num.Number { - max = num.Number + if num := maxRange[ref.Row][ref.Col].ToNumber(); num.Type == ArgNumber && maxVal < num.Number { + maxVal = num.Number } } - if max == -math.MaxFloat64 { - max = 0 + if maxVal == -math.MaxFloat64 { + maxVal = 0 } - return newNumberFormulaArg(max) + return newNumberFormulaArg(maxVal) } // calcListMatrixMax is part of the implementation max. -func calcListMatrixMax(maxa bool, max float64, arg formulaArg) float64 { +func calcListMatrixMax(maxa bool, maxVal float64, arg formulaArg) float64 { for _, cell := range arg.ToList() { - if cell.Type == ArgNumber && cell.Number > max { + if cell.Type == ArgNumber && cell.Number > maxVal { if maxa && cell.Boolean || !cell.Boolean { - max = cell.Number + maxVal = cell.Number } } } - return max + return maxVal } -// max is an implementation of the formula functions MAX and MAXA. -func (fn *formulaFuncs) max(maxa bool, argsList *list.List) formulaArg { - max := -math.MaxFloat64 +// maxValue is an implementation of the formula functions MAX and MAXA. +func (fn *formulaFuncs) maxValue(maxa bool, argsList *list.List) formulaArg { + maxVal := -math.MaxFloat64 for token := argsList.Front(); token != nil; token = token.Next() { arg := token.Value.(formulaArg) switch arg.Type { @@ -10069,29 +10087,29 @@ func (fn *formulaFuncs) max(maxa bool, argsList *list.List) formulaArg { continue } else { num := arg.ToBool() - if num.Type == ArgNumber && num.Number > max { - max = num.Number + if num.Type == ArgNumber && num.Number > maxVal { + maxVal = num.Number continue } } num := arg.ToNumber() - if num.Type != ArgError && num.Number > max { - max = num.Number + if num.Type != ArgError && num.Number > maxVal { + maxVal = num.Number } case ArgNumber: - if arg.Number > max { - max = arg.Number + if arg.Number > maxVal { + maxVal = arg.Number } case ArgList, ArgMatrix: - max = calcListMatrixMax(maxa, max, arg) + maxVal = calcListMatrixMax(maxa, maxVal, arg) case ArgError: return arg } } - if max == -math.MaxFloat64 { - max = 0 + if maxVal == -math.MaxFloat64 { + maxVal = 0 } - return newNumberFormulaArg(max) + return newNumberFormulaArg(maxVal) } // MEDIAN function returns the statistical median (the middle value) of a list @@ -10145,7 +10163,7 @@ func (fn *formulaFuncs) MIN(argsList *list.List) formulaArg { if argsList.Len() == 0 { return newErrorFormulaArg(formulaErrorVALUE, "MIN requires at least 1 argument") } - return fn.min(false, argsList) + return fn.minValue(false, argsList) } // MINA function returns the smallest value from a supplied set of numeric @@ -10158,7 +10176,7 @@ func (fn *formulaFuncs) MINA(argsList *list.List) formulaArg { if argsList.Len() == 0 { return newErrorFormulaArg(formulaErrorVALUE, "MINA requires at least 1 argument") } - return fn.min(true, argsList) + return fn.minValue(true, argsList) } // MINIFS function returns the minimum value from a subset of values that are @@ -10174,36 +10192,36 @@ func (fn *formulaFuncs) MINIFS(argsList *list.List) formulaArg { return newErrorFormulaArg(formulaErrorNA, formulaErrorNA) } var args []formulaArg - min, minRange := math.MaxFloat64, argsList.Front().Value.(formulaArg).Matrix + minVal, minRange := math.MaxFloat64, argsList.Front().Value.(formulaArg).Matrix for arg := argsList.Front().Next(); arg != nil; arg = arg.Next() { args = append(args, arg.Value.(formulaArg)) } for _, ref := range formulaIfsMatch(args) { - if num := minRange[ref.Row][ref.Col].ToNumber(); num.Type == ArgNumber && min > num.Number { - min = num.Number + if num := minRange[ref.Row][ref.Col].ToNumber(); num.Type == ArgNumber && minVal > num.Number { + minVal = num.Number } } - if min == math.MaxFloat64 { - min = 0 + if minVal == math.MaxFloat64 { + minVal = 0 } - return newNumberFormulaArg(min) + return newNumberFormulaArg(minVal) } // calcListMatrixMin is part of the implementation min. -func calcListMatrixMin(mina bool, min float64, arg formulaArg) float64 { +func calcListMatrixMin(mina bool, minVal float64, arg formulaArg) float64 { for _, cell := range arg.ToList() { - if cell.Type == ArgNumber && cell.Number < min { + if cell.Type == ArgNumber && cell.Number < minVal { if mina && cell.Boolean || !cell.Boolean { - min = cell.Number + minVal = cell.Number } } } - return min + return minVal } -// min is an implementation of the formula functions MIN and MINA. -func (fn *formulaFuncs) min(mina bool, argsList *list.List) formulaArg { - min := math.MaxFloat64 +// minValue is an implementation of the formula functions MIN and MINA. +func (fn *formulaFuncs) minValue(mina bool, argsList *list.List) formulaArg { + minVal := math.MaxFloat64 for token := argsList.Front(); token != nil; token = token.Next() { arg := token.Value.(formulaArg) switch arg.Type { @@ -10212,29 +10230,29 @@ func (fn *formulaFuncs) min(mina bool, argsList *list.List) formulaArg { continue } else { num := arg.ToBool() - if num.Type == ArgNumber && num.Number < min { - min = num.Number + if num.Type == ArgNumber && num.Number < minVal { + minVal = num.Number continue } } num := arg.ToNumber() - if num.Type != ArgError && num.Number < min { - min = num.Number + if num.Type != ArgError && num.Number < minVal { + minVal = num.Number } case ArgNumber: - if arg.Number < min { - min = arg.Number + if arg.Number < minVal { + minVal = arg.Number } case ArgList, ArgMatrix: - min = calcListMatrixMin(mina, min, arg) + minVal = calcListMatrixMin(mina, minVal, arg) case ArgError: return arg } } - if min == math.MaxFloat64 { - min = 0 + if minVal == math.MaxFloat64 { + minVal = 0 } - return newNumberFormulaArg(min) + return newNumberFormulaArg(minVal) } // pearsonProduct is an implementation of the formula functions FORECAST, @@ -13554,7 +13572,7 @@ func (fn *formulaFuncs) code(name string, argsList *list.List) formulaArg { // // CONCAT(text1,[text2],...) func (fn *formulaFuncs) CONCAT(argsList *list.List) formulaArg { - return fn.concat("CONCAT", argsList) + return fn.concat(argsList) } // CONCATENATE function joins together a series of supplied text strings into @@ -13562,12 +13580,12 @@ func (fn *formulaFuncs) CONCAT(argsList *list.List) formulaArg { // // CONCATENATE(text1,[text2],...) func (fn *formulaFuncs) CONCATENATE(argsList *list.List) formulaArg { - return fn.concat("CONCATENATE", argsList) + return fn.concat(argsList) } // concat is an implementation of the formula functions CONCAT and // CONCATENATE. -func (fn *formulaFuncs) concat(name string, argsList *list.List) formulaArg { +func (fn *formulaFuncs) concat(argsList *list.List) formulaArg { var buf bytes.Buffer for arg := argsList.Front(); arg != nil; arg = arg.Next() { for _, cell := range arg.Value.(formulaArg).ToList() { @@ -13831,16 +13849,16 @@ func (fn *formulaFuncs) LENB(argsList *list.List) formulaArg { if argsList.Len() != 1 { return newErrorFormulaArg(formulaErrorVALUE, "LENB requires 1 string argument") } - bytes := 0 + result := 0 for _, r := range argsList.Front().Value.(formulaArg).Value() { b := utf8.RuneLen(r) if b == 1 { - bytes++ + result++ } else if b > 1 { - bytes += 2 + result += 2 } } - return newNumberFormulaArg(float64(bytes)) + return newNumberFormulaArg(float64(result)) } // LOWER converts all characters in a supplied text string to lower case. The @@ -14774,7 +14792,7 @@ func (fn *formulaFuncs) COLUMN(argsList *list.List) formulaArg { // calcColsRowsMinMax calculation min and max value for given formula arguments // sequence of the formula functions COLUMNS and ROWS. -func calcColsRowsMinMax(cols bool, argsList *list.List) (min, max int) { +func calcColsRowsMinMax(cols bool, argsList *list.List) (minVal, maxVal int) { getVal := func(cols bool, cell cellRef) int { if cols { return cell.Col @@ -14784,22 +14802,22 @@ func calcColsRowsMinMax(cols bool, argsList *list.List) (min, max int) { if argsList.Front().Value.(formulaArg).cellRanges != nil && argsList.Front().Value.(formulaArg).cellRanges.Len() > 0 { crs := argsList.Front().Value.(formulaArg).cellRanges for cr := crs.Front(); cr != nil; cr = cr.Next() { - if min == 0 { - min = getVal(cols, cr.Value.(cellRange).From) + if minVal == 0 { + minVal = getVal(cols, cr.Value.(cellRange).From) } - if max < getVal(cols, cr.Value.(cellRange).To) { - max = getVal(cols, cr.Value.(cellRange).To) + if maxVal < getVal(cols, cr.Value.(cellRange).To) { + maxVal = getVal(cols, cr.Value.(cellRange).To) } } } if argsList.Front().Value.(formulaArg).cellRefs != nil && argsList.Front().Value.(formulaArg).cellRefs.Len() > 0 { cr := argsList.Front().Value.(formulaArg).cellRefs for refs := cr.Front(); refs != nil; refs = refs.Next() { - if min == 0 { - min = getVal(cols, refs.Value.(cellRef)) + if minVal == 0 { + minVal = getVal(cols, refs.Value.(cellRef)) } - if max < getVal(cols, refs.Value.(cellRef)) { - max = getVal(cols, refs.Value.(cellRef)) + if maxVal < getVal(cols, refs.Value.(cellRef)) { + maxVal = getVal(cols, refs.Value.(cellRef)) } } } @@ -14814,13 +14832,13 @@ func (fn *formulaFuncs) COLUMNS(argsList *list.List) formulaArg { if argsList.Len() != 1 { return newErrorFormulaArg(formulaErrorVALUE, "COLUMNS requires 1 argument") } - min, max := calcColsRowsMinMax(true, argsList) - if max == MaxColumns { + minVal, maxVal := calcColsRowsMinMax(true, argsList) + if maxVal == MaxColumns { return newNumberFormulaArg(float64(MaxColumns)) } - result := max - min + 1 - if max == min { - if min == 0 { + result := maxVal - minVal + 1 + if maxVal == minVal { + if minVal == 0 { return newErrorFormulaArg(formulaErrorVALUE, "invalid reference") } return newNumberFormulaArg(float64(1)) @@ -15555,13 +15573,13 @@ func (fn *formulaFuncs) ROWS(argsList *list.List) formulaArg { if argsList.Len() != 1 { return newErrorFormulaArg(formulaErrorVALUE, "ROWS requires 1 argument") } - min, max := calcColsRowsMinMax(false, argsList) - if max == TotalRows { + minVal, maxVal := calcColsRowsMinMax(false, argsList) + if maxVal == TotalRows { return newNumberFormulaArg(TotalRows) } - result := max - min + 1 - if max == min { - if min == 0 { + result := maxVal - minVal + 1 + if maxVal == minVal { + if minVal == 0 { return newErrorFormulaArg(formulaErrorVALUE, "invalid reference") } return newNumberFormulaArg(float64(1)) diff --git a/col.go b/col.go index c51fdad..b1b9c0d 100644 --- a/col.go +++ b/col.go @@ -354,20 +354,20 @@ func (f *File) GetColOutlineLevel(sheet, col string) (uint8, error) { } // parseColRange parse and convert column range with column name to the column number. -func (f *File) parseColRange(columns string) (min, max int, err error) { +func (f *File) parseColRange(columns string) (minVal, maxVal int, err error) { colsTab := strings.Split(columns, ":") - min, err = ColumnNameToNumber(colsTab[0]) + minVal, err = ColumnNameToNumber(colsTab[0]) if err != nil { return } - max = min + maxVal = minVal if len(colsTab) == 2 { - if max, err = ColumnNameToNumber(colsTab[1]); err != nil { + if maxVal, err = ColumnNameToNumber(colsTab[1]); err != nil { return } } - if max < min { - min, max = max, min + if maxVal < minVal { + minVal, maxVal = maxVal, minVal } return } diff --git a/date_test.go b/date_test.go index 4091e37..11011cf 100644 --- a/date_test.go +++ b/date_test.go @@ -68,22 +68,22 @@ func TestTimeFromExcelTime(t *testing.T) { }) } for hour := 0; hour < 24; hour++ { - for min := 0; min < 60; min++ { + for minVal := 0; minVal < 60; minVal++ { for sec := 0; sec < 60; sec++ { - date := time.Date(2021, time.December, 30, hour, min, sec, 0, time.UTC) + date := time.Date(2021, time.December, 30, hour, minVal, sec, 0, time.UTC) // Test use 1900 date system excel1900Time, err := timeToExcelTime(date, false) assert.NoError(t, err) date1900Out := timeFromExcelTime(excel1900Time, false) assert.EqualValues(t, hour, date1900Out.Hour()) - assert.EqualValues(t, min, date1900Out.Minute()) + assert.EqualValues(t, minVal, date1900Out.Minute()) assert.EqualValues(t, sec, date1900Out.Second()) // Test use 1904 date system excel1904Time, err := timeToExcelTime(date, true) assert.NoError(t, err) date1904Out := timeFromExcelTime(excel1904Time, true) assert.EqualValues(t, hour, date1904Out.Hour()) - assert.EqualValues(t, min, date1904Out.Minute()) + assert.EqualValues(t, minVal, date1904Out.Minute()) assert.EqualValues(t, sec, date1904Out.Second()) } } diff --git a/drawing.go b/drawing.go index bc7b8a4..3c2da06 100644 --- a/drawing.go +++ b/drawing.go @@ -980,21 +980,21 @@ func (f *File) drawChartSeriesDLbls(i int, opts *Chart) *cDLbls { // drawPlotAreaCatAx provides a function to draw the c:catAx element. func (f *File) drawPlotAreaCatAx(opts *Chart) []*cAxs { - max := &attrValFloat{Val: opts.XAxis.Maximum} - min := &attrValFloat{Val: opts.XAxis.Minimum} + maxVal := &attrValFloat{Val: opts.XAxis.Maximum} + minVal := &attrValFloat{Val: opts.XAxis.Minimum} if opts.XAxis.Maximum == nil { - max = nil + maxVal = nil } if opts.XAxis.Minimum == nil { - min = nil + minVal = nil } axs := []*cAxs{ { AxID: &attrValInt{Val: intPtr(100000000)}, Scaling: &cScaling{ Orientation: &attrValString{Val: stringPtr(orientation[opts.XAxis.ReverseOrder])}, - Max: max, - Min: min, + Max: maxVal, + Min: minVal, }, Delete: &attrValBool{Val: boolPtr(opts.XAxis.None)}, AxPos: &attrValString{Val: stringPtr(catAxPos[opts.XAxis.ReverseOrder])}, @@ -1030,8 +1030,8 @@ func (f *File) drawPlotAreaCatAx(opts *Chart) []*cAxs { AxID: &attrValInt{Val: intPtr(opts.XAxis.axID)}, Scaling: &cScaling{ Orientation: &attrValString{Val: stringPtr(orientation[opts.XAxis.ReverseOrder])}, - Max: max, - Min: min, + Max: maxVal, + Min: minVal, }, Delete: &attrValBool{Val: boolPtr(true)}, AxPos: &attrValString{Val: stringPtr("b")}, @@ -1052,13 +1052,13 @@ func (f *File) drawPlotAreaCatAx(opts *Chart) []*cAxs { // drawPlotAreaValAx provides a function to draw the c:valAx element. func (f *File) drawPlotAreaValAx(opts *Chart) []*cAxs { - max := &attrValFloat{Val: opts.YAxis.Maximum} - min := &attrValFloat{Val: opts.YAxis.Minimum} + maxVal := &attrValFloat{Val: opts.YAxis.Maximum} + minVal := &attrValFloat{Val: opts.YAxis.Minimum} if opts.YAxis.Maximum == nil { - max = nil + maxVal = nil } if opts.YAxis.Minimum == nil { - min = nil + minVal = nil } var logBase *attrValFloat if opts.YAxis.LogBase >= 2 && opts.YAxis.LogBase <= 1000 { @@ -1070,8 +1070,8 @@ func (f *File) drawPlotAreaValAx(opts *Chart) []*cAxs { Scaling: &cScaling{ LogBase: logBase, Orientation: &attrValString{Val: stringPtr(orientation[opts.YAxis.ReverseOrder])}, - Max: max, - Min: min, + Max: maxVal, + Min: minVal, }, Delete: &attrValBool{Val: boolPtr(opts.YAxis.None)}, AxPos: &attrValString{Val: stringPtr(valAxPos[opts.YAxis.ReverseOrder])}, @@ -1109,8 +1109,8 @@ func (f *File) drawPlotAreaValAx(opts *Chart) []*cAxs { AxID: &attrValInt{Val: intPtr(opts.YAxis.axID)}, Scaling: &cScaling{ Orientation: &attrValString{Val: stringPtr(orientation[opts.YAxis.ReverseOrder])}, - Max: max, - Min: min, + Max: maxVal, + Min: minVal, }, Delete: &attrValBool{Val: boolPtr(false)}, AxPos: &attrValString{Val: stringPtr("r")}, @@ -1129,21 +1129,21 @@ func (f *File) drawPlotAreaValAx(opts *Chart) []*cAxs { // drawPlotAreaSerAx provides a function to draw the c:serAx element. func (f *File) drawPlotAreaSerAx(opts *Chart) []*cAxs { - max := &attrValFloat{Val: opts.YAxis.Maximum} - min := &attrValFloat{Val: opts.YAxis.Minimum} + maxVal := &attrValFloat{Val: opts.YAxis.Maximum} + minVal := &attrValFloat{Val: opts.YAxis.Minimum} if opts.YAxis.Maximum == nil { - max = nil + maxVal = nil } if opts.YAxis.Minimum == nil { - min = nil + minVal = nil } return []*cAxs{ { AxID: &attrValInt{Val: intPtr(100000005)}, Scaling: &cScaling{ Orientation: &attrValString{Val: stringPtr(orientation[opts.YAxis.ReverseOrder])}, - Max: max, - Min: min, + Max: maxVal, + Min: minVal, }, Delete: &attrValBool{Val: boolPtr(opts.YAxis.None)}, AxPos: &attrValString{Val: stringPtr(catAxPos[opts.XAxis.ReverseOrder])}, diff --git a/excelize.go b/excelize.go index 152e212..87ef22d 100644 --- a/excelize.go +++ b/excelize.go @@ -334,9 +334,9 @@ func (ws *xlsxWorksheet) checkSheet() { // with r="0" attribute. func (ws *xlsxWorksheet) checkSheetRows() (int, []xlsxRow) { var ( - row, max int - r0 []xlsxRow - maxRowNum = func(num int, c []xlsxC) int { + row, maxVal int + r0 []xlsxRow + maxRowNum = func(num int, c []xlsxC) int { for _, cell := range c { if _, n, err := CellNameToCoordinates(cell.R); err == nil && n > num { num = n @@ -351,8 +351,8 @@ func (ws *xlsxWorksheet) checkSheetRows() (int, []xlsxRow) { continue } if i == 0 && *r.R == 0 { - if num := maxRowNum(row, r.C); num > max { - max = num + if num := maxRowNum(row, r.C); num > maxVal { + maxVal = num } r0 = append(r0, r) continue @@ -361,8 +361,8 @@ func (ws *xlsxWorksheet) checkSheetRows() (int, []xlsxRow) { row = *r.R } } - if max > row { - row = max + if maxVal > row { + row = maxVal } return row, r0 } diff --git a/go.mod b/go.mod index 958af04..357b84e 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/stretchr/testify v1.8.4 github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 - golang.org/x/crypto v0.18.0 + golang.org/x/crypto v0.19.0 golang.org/x/image v0.14.0 - golang.org/x/net v0.20.0 + golang.org/x/net v0.21.0 golang.org/x/text v0.14.0 ) diff --git a/go.sum b/go.sum index 9928182..64de49a 100644 --- a/go.sum +++ b/go.sum @@ -15,12 +15,12 @@ github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 h1:Chd9DkqERQQuHpXjR/HSV1 github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI= github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 h1:qhbILQo1K3mphbwKh1vNm4oGezE1eF9fQWmNiIpSfI4= github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= +golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= +golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/image v0.14.0 h1:tNgSxAFe3jC4uYqvZdTr84SZoM1KfwdC9SKIFrLjFn4= golang.org/x/image v0.14.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= diff --git a/hsl.go b/hsl.go index 68ddf21..b8fb77b 100644 --- a/hsl.go +++ b/hsl.go @@ -65,21 +65,21 @@ func RGBToHSL(r, g, b uint8) (h, s, l float64) { fR := float64(r) / 255 fG := float64(g) / 255 fB := float64(b) / 255 - max := math.Max(math.Max(fR, fG), fB) - min := math.Min(math.Min(fR, fG), fB) - l = (max + min) / 2 - if max == min { + maxVal := math.Max(math.Max(fR, fG), fB) + minVal := math.Min(math.Min(fR, fG), fB) + l = (maxVal + minVal) / 2 + if maxVal == minVal { // Achromatic. h, s = 0, 0 } else { // Chromatic. - d := max - min + d := maxVal - minVal if l > 0.5 { - s = d / (2.0 - max - min) + s = d / (2.0 - maxVal - minVal) } else { - s = d / (max + min) + s = d / (maxVal + minVal) } - switch max { + switch maxVal { case fR: h = (fG - fB) / d if fG < fB { diff --git a/numfmt.go b/numfmt.go index c4022ba..d37130b 100644 --- a/numfmt.go +++ b/numfmt.go @@ -5776,7 +5776,7 @@ func localMonthsNameKiche(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesKiche[int(t.Month())-1] } - return string([]rune(monthNamesKicheAbbr[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesKicheAbbr[(t.Month() - 1)])[:1]) } // localMonthsNameKinyarwanda returns the Kinyarwanda name of the month. @@ -5787,7 +5787,7 @@ func localMonthsNameKinyarwanda(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesKinyarwanda[int(t.Month())-1] } - return string([]rune(monthNamesKinyarwanda[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesKinyarwanda[(t.Month() - 1)])[:1]) } // localMonthsNameKiswahili returns the Kiswahili name of the month. @@ -5798,7 +5798,7 @@ func localMonthsNameKiswahili(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesKiswahili[int(t.Month())-1] } - return string([]rune(monthNamesKiswahili[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesKiswahili[(t.Month() - 1)])[:1]) } // localMonthsNameKonkani returns the Konkani name of the month. @@ -5809,7 +5809,7 @@ func localMonthsNameKonkani(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesKonkani[int(t.Month())-1] } - return string([]rune(monthNamesKonkani[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesKonkani[(t.Month() - 1)])[:1]) } // localMonthsNameKorean returns the Korean name of the month. @@ -5828,7 +5828,7 @@ func localMonthsNameKyrgyz(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesKyrgyz[int(t.Month())-1] } - return string([]rune(monthNamesKyrgyz[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesKyrgyz[(t.Month() - 1)])[:1]) } // localMonthsNameLao returns the Lao name of the month. @@ -5839,7 +5839,7 @@ func localMonthsNameLao(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesLao[int(t.Month())-1] } - return string([]rune(monthNamesLao[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesLao[(t.Month() - 1)])[:1]) } // localMonthsNameLatin returns the Latin name of the month. @@ -5850,7 +5850,7 @@ func localMonthsNameLatin(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesLatin[int(t.Month())-1] } - return string([]rune(monthNamesLatin[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesLatin[(t.Month() - 1)])[:1]) } // localMonthsNameLatvian returns the Latvian name of the month. @@ -5861,7 +5861,7 @@ func localMonthsNameLatvian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesLatvian[int(t.Month())-1] } - return string([]rune(monthNamesLatvian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesLatvian[(t.Month() - 1)])[:1]) } // localMonthsNameLithuanian returns the Lithuanian name of the month. @@ -5872,7 +5872,7 @@ func localMonthsNameLithuanian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesLithuanian[int(t.Month())-1] } - return string([]rune(monthNamesLithuanian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesLithuanian[(t.Month() - 1)])[:1]) } // localMonthsNameLowerSorbian returns the LowerSorbian name of the month. @@ -5883,7 +5883,7 @@ func localMonthsNameLowerSorbian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesLowerSorbian[int(t.Month())-1] } - return string([]rune(monthNamesLowerSorbian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesLowerSorbian[(t.Month() - 1)])[:1]) } // localMonthsNameLuxembourgish returns the Luxembourgish name of the month. @@ -5894,7 +5894,7 @@ func localMonthsNameLuxembourgish(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesLuxembourgish[int(t.Month())-1] } - return string([]rune(monthNamesLuxembourgish[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesLuxembourgish[(t.Month() - 1)])[:1]) } // localMonthsNameMacedonian returns the Macedonian name of the month. @@ -5905,7 +5905,7 @@ func localMonthsNameMacedonian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMacedonian[int(t.Month())-1] } - return string([]rune(monthNamesMacedonian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMacedonian[(t.Month() - 1)])[:1]) } // localMonthsNameMalay returns the Malay name of the month. @@ -5916,7 +5916,7 @@ func localMonthsNameMalay(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMalay[int(t.Month())-1] } - return string([]rune(monthNamesMalay[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMalay[(t.Month() - 1)])[:1]) } // localMonthsNameMalayalam returns the Malayalam name of the month. @@ -5927,7 +5927,7 @@ func localMonthsNameMalayalam(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMalayalam[int(t.Month())-1] } - return string([]rune(monthNamesMalayalam[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMalayalam[(t.Month() - 1)])[:1]) } // localMonthsNameMaltese returns the Maltese name of the month. @@ -5938,7 +5938,7 @@ func localMonthsNameMaltese(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMaltese[int(t.Month())-1] } - return string([]rune(monthNamesMaltese[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMaltese[(t.Month() - 1)])[:1]) } // localMonthsNameMaori returns the Maori name of the month. @@ -5949,13 +5949,13 @@ func localMonthsNameMaori(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMaori[int(t.Month())-1] } - return string([]rune(monthNamesMaori[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMaori[(t.Month() - 1)])[:1]) } // localMonthsNameMapudungun returns the Mapudungun name of the month. func localMonthsNameMapudungun(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesMapudungun[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMapudungun[(t.Month() - 1)])[:1]) } return monthNamesMapudungun[int(t.Month())-1] } @@ -5968,7 +5968,7 @@ func localMonthsNameMarathi(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMarathi[int(t.Month())-1] } - return string([]rune(monthNamesMarathi[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMarathi[(t.Month() - 1)])[:1]) } // localMonthsNameMohawk returns the Mohawk name of the month. @@ -5979,7 +5979,7 @@ func localMonthsNameMohawk(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMohawk[int(t.Month())-1] } - return string([]rune(monthNamesMohawk[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMohawk[(t.Month() - 1)])[:1]) } // localMonthsNameMongolian returns the Mongolian name of the month. @@ -5990,7 +5990,7 @@ func localMonthsNameMongolian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesMongolian[int(t.Month())-1] } - return string([]rune(monthNamesMongolian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesMongolian[(t.Month() - 1)])[:1]) } // localMonthsNameMorocco returns the Morocco name of the month. @@ -6012,7 +6012,7 @@ func localMonthsNameNepali(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesNepali[int(t.Month())-1] } - return string([]rune(monthNamesNepali[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesNepali[(t.Month() - 1)])[:1]) } // localMonthsNameNepaliIN returns the India Nepali name of the month. @@ -6023,7 +6023,7 @@ func localMonthsNameNepaliIN(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesNepaliIN[int(t.Month())-1] } - return string([]rune(monthNamesNepaliIN[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesNepaliIN[(t.Month() - 1)])[:1]) } // localMonthsNameNigeria returns the Nigeria name of the month. @@ -6045,7 +6045,7 @@ func localMonthsNameNorwegian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesNorwegian[int(t.Month())-1] } - return string([]rune(monthNamesNorwegian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesNorwegian[(t.Month() - 1)])[:1]) } // localMonthsNameOccitan returns the Occitan name of the month. @@ -6056,13 +6056,13 @@ func localMonthsNameOccitan(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesOccitan[int(t.Month())-1] } - return string([]rune(monthNamesOccitan[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesOccitan[(t.Month() - 1)])[:1]) } // localMonthsNameOdia returns the Odia name of the month. func localMonthsNameOdia(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesOdia[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesOdia[(t.Month() - 1)])[:1]) } return monthNamesOdia[int(t.Month())-1] } @@ -6075,7 +6075,7 @@ func localMonthsNameOromo(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesOromo[int(t.Month())-1] } - return string([]rune(monthNamesOromo[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesOromo[(t.Month() - 1)])[:1]) } // localMonthsNamePashto returns the Pashto name of the month. @@ -6094,7 +6094,7 @@ func localMonthsNamePashto(t time.Time, abbr int) string { // localMonthsNamePersian returns the Persian name of the month. func localMonthsNamePersian(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesPersian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesPersian[(t.Month() - 1)])[:1]) } return monthNamesPersian[int(t.Month())-1] } @@ -6102,29 +6102,29 @@ func localMonthsNamePersian(t time.Time, abbr int) string { // localMonthsNamePolish returns the Polish name of the month. func localMonthsNamePolish(t time.Time, abbr int) string { if abbr == 3 { - return string([]rune(monthNamesPolish[int(t.Month()-1)])[:3]) + return string([]rune(monthNamesPolish[(t.Month() - 1)])[:3]) } if abbr == 4 || abbr > 6 { return monthNamesPolish[int(t.Month())-1] } - return string([]rune(monthNamesPolish[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesPolish[(t.Month() - 1)])[:1]) } // localMonthsNamePortuguese returns the Portuguese name of the month. func localMonthsNamePortuguese(t time.Time, abbr int) string { if abbr == 3 { - return string([]rune(monthNamesPortuguese[int(t.Month()-1)])[:3]) + return string([]rune(monthNamesPortuguese[(t.Month() - 1)])[:3]) } if abbr == 4 || abbr > 6 { return monthNamesPortuguese[int(t.Month())-1] } - return string([]rune(monthNamesPortuguese[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesPortuguese[(t.Month() - 1)])[:1]) } // localMonthsNamePunjabi returns the Punjabi name of the month. func localMonthsNamePunjabi(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesPunjabi[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesPunjabi[(t.Month() - 1)])[:1]) } return monthNamesPunjabi[int(t.Month())-1] } @@ -6132,7 +6132,7 @@ func localMonthsNamePunjabi(t time.Time, abbr int) string { // localMonthsNamePunjabiArab returns the Punjabi Arab name of the month. func localMonthsNamePunjabiArab(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesPunjabiArab[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesPunjabiArab[(t.Month() - 1)])[:1]) } return monthNamesPunjabiArab[int(t.Month())-1] } @@ -6140,26 +6140,26 @@ func localMonthsNamePunjabiArab(t time.Time, abbr int) string { // localMonthsNameQuechua returns the Quechua name of the month. func localMonthsNameQuechua(t time.Time, abbr int) string { if abbr == 3 { - return string([]rune(monthNamesQuechua[int(t.Month()-1)])[:3]) + return string([]rune(monthNamesQuechua[(t.Month() - 1)])[:3]) } if abbr == 4 || abbr > 6 { return monthNamesQuechua[int(t.Month())-1] } - return string([]rune(monthNamesQuechua[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesQuechua[(t.Month() - 1)])[:1]) } // localMonthsNameQuechuaEcuador returns the QuechuaEcuador name of the month. func localMonthsNameQuechuaEcuador(t time.Time, abbr int) string { if abbr == 3 { if int(t.Month()) == 1 { - return string([]rune(monthNamesQuechuaEcuador[int(t.Month()-1)])[:4]) + return string([]rune(monthNamesQuechuaEcuador[(t.Month() - 1)])[:4]) } - return string([]rune(monthNamesQuechuaEcuador[int(t.Month()-1)])[:3]) + return string([]rune(monthNamesQuechuaEcuador[(t.Month() - 1)])[:3]) } if abbr == 4 || abbr > 6 { return monthNamesQuechuaEcuador[int(t.Month())-1] } - return string([]rune(monthNamesQuechuaEcuador[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesQuechuaEcuador[(t.Month() - 1)])[:1]) } // localMonthsNameRomanian returns the Romanian name of the month. @@ -6170,7 +6170,7 @@ func localMonthsNameRomanian(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesRomanian[int(t.Month())-1] } - return string([]rune(monthNamesRomanian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesRomanian[(t.Month() - 1)])[:1]) } // localMonthsNameRomansh returns the Romansh name of the month. @@ -6181,7 +6181,7 @@ func localMonthsNameRomansh(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesRomansh[int(t.Month())-1] } - return string([]rune(monthNamesRomansh[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesRomansh[(t.Month() - 1)])[:1]) } // localMonthsNameRussian returns the Russian name of the month. @@ -6207,7 +6207,7 @@ func localMonthsNameSakha(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesSakha[int(t.Month())-1] } - return string([]rune(monthNamesSakha[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSakha[(t.Month() - 1)])[:1]) } // localMonthsNameSami returns the Sami name of the month. @@ -6218,7 +6218,7 @@ func localMonthsNameSami(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesSami[int(t.Month())-1] } - return string([]rune(monthNamesSami[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSami[(t.Month() - 1)])[:1]) } // localMonthsNameSamiLule returns the Sami (Lule) name of the month. @@ -6229,25 +6229,25 @@ func localMonthsNameSamiLule(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesSamiLule[int(t.Month())-1] } - return string([]rune(monthNamesSamiLule[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSamiLule[(t.Month() - 1)])[:1]) } // localMonthsNameSamiNorthern returns the Sami (Northern) name of the month. func localMonthsNameSamiNorthern(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSamiNorthernAbbr[int(t.Month()-1)] + return monthNamesSamiNorthernAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSamiNorthern[int(t.Month())-1] } - return string([]rune(monthNamesSamiNorthern[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSamiNorthern[(t.Month() - 1)])[:1]) } // localMonthsNameSamiNorthernFI returns the Sami (Northern) Finland name of the // month. func localMonthsNameSamiNorthernFI(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSamiNorthernAbbr[int(t.Month()-1)] + return monthNamesSamiNorthernAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { if int(t.Month()) == 1 { @@ -6255,13 +6255,13 @@ func localMonthsNameSamiNorthernFI(t time.Time, abbr int) string { } return monthNamesSamiNorthern[int(t.Month())-1] } - return string([]rune(monthNamesSamiNorthern[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSamiNorthern[(t.Month() - 1)])[:1]) } // localMonthsNameSamiSkolt returns the Sami (Skolt) name of the month. func localMonthsNameSamiSkolt(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesSamiSkolt[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSamiSkolt[(t.Month() - 1)])[:1]) } return monthNamesSamiSkolt[int(t.Month())-1] } @@ -6269,18 +6269,18 @@ func localMonthsNameSamiSkolt(t time.Time, abbr int) string { // localMonthsNameSamiSouthern returns the Sami (Southern) name of the month. func localMonthsNameSamiSouthern(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSamiSouthernAbbr[int(t.Month()-1)] + return monthNamesSamiSouthernAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSamiSouthern[int(t.Month())-1] } - return string([]rune(monthNamesSamiSouthern[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSamiSouthern[(t.Month() - 1)])[:1]) } // localMonthsNameSanskrit returns the Sanskrit name of the month. func localMonthsNameSanskrit(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesSanskrit[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSanskrit[(t.Month() - 1)])[:1]) } return monthNamesSanskrit[int(t.Month())-1] } @@ -6288,85 +6288,85 @@ func localMonthsNameSanskrit(t time.Time, abbr int) string { // localMonthsNameScottishGaelic returns the Scottish Gaelic name of the month. func localMonthsNameScottishGaelic(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesScottishGaelicAbbr[int(t.Month()-1)] + return monthNamesScottishGaelicAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesScottishGaelic[int(t.Month())-1] } - return string([]rune(monthNamesScottishGaelic[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesScottishGaelic[(t.Month() - 1)])[:1]) } // localMonthsNameSerbian returns the Serbian (Cyrillic) name of the month. func localMonthsNameSerbian(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSerbianAbbr[int(t.Month()-1)] + return monthNamesSerbianAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSerbian[int(t.Month())-1] } - return string([]rune(monthNamesSerbian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSerbian[(t.Month() - 1)])[:1]) } // localMonthsNameSerbianBA returns the Serbian (Cyrillic) Bosnia and // Herzegovina name of the month. func localMonthsNameSerbianBA(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSerbianBAAbbr[int(t.Month()-1)] + return monthNamesSerbianBAAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSerbianBA[int(t.Month())-1] } - return string([]rune(monthNamesSerbianBA[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSerbianBA[(t.Month() - 1)])[:1]) } // localMonthsNameSerbianLatin returns the Serbian (Latin) name of the month. func localMonthsNameSerbianLatin(t time.Time, abbr int) string { if abbr == 3 { - return string([]rune(monthNamesSerbianLatin[int(t.Month()-1)])[:3]) + return string([]rune(monthNamesSerbianLatin[(t.Month() - 1)])[:3]) } if abbr == 4 || abbr > 6 { return monthNamesSerbianLatin[int(t.Month())-1] } - return string([]rune(monthNamesSerbianLatin[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSerbianLatin[(t.Month() - 1)])[:1]) } // localMonthsNameSerbianLatinCS returns the Serbian (Latin) name of the month. func localMonthsNameSerbianLatinCS(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSerbianLatinAbbr[int(t.Month()-1)] + return monthNamesSerbianLatinAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSerbianLatin[int(t.Month())-1] } - return string([]rune(monthNamesSerbianLatin[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSerbianLatin[(t.Month() - 1)])[:1]) } // localMonthsNameSesothoSaLeboa returns the Sesotho sa Leboa name of the month. func localMonthsNameSesothoSaLeboa(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSesothoSaLeboaAbbr[int(t.Month()-1)] + return monthNamesSesothoSaLeboaAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSesothoSaLeboa[int(t.Month())-1] } - return string([]rune(monthNamesSesothoSaLeboa[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSesothoSaLeboa[(t.Month() - 1)])[:1]) } // localMonthsNameSetswana returns the Setswana name of the month. func localMonthsNameSetswana(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSetswanaAbbr[int(t.Month()-1)] + return monthNamesSetswanaAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSetswana[int(t.Month())-1] } - return string([]rune(monthNamesSetswana[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSetswana[(t.Month() - 1)])[:1]) } // localMonthsNameSindhi returns the Sindhi name of the month. func localMonthsNameSindhi(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesSindhi[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSindhi[(t.Month() - 1)])[:1]) } return monthNamesSindhi[int(t.Month())-1] } @@ -6374,12 +6374,12 @@ func localMonthsNameSindhi(t time.Time, abbr int) string { // localMonthsNameSinhala returns the Sinhala name of the month. func localMonthsNameSinhala(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSinhalaAbbr[int(t.Month()-1)] + return monthNamesSinhalaAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSinhala[int(t.Month())-1] } - return string([]rune(monthNamesSinhala[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSinhala[(t.Month() - 1)])[:1]) } // localMonthsNameSlovak returns the Slovak name of the month. @@ -6390,40 +6390,40 @@ func localMonthsNameSlovak(t time.Time, abbr int) string { if abbr == 4 || abbr > 6 { return monthNamesSlovak[int(t.Month())-1] } - return string([]rune(monthNamesSlovak[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSlovak[(t.Month() - 1)])[:1]) } // localMonthsNameSlovenian returns the Slovenian name of the month. func localMonthsNameSlovenian(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSlovenianAbbr[int(t.Month()-1)] + return monthNamesSlovenianAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSlovenian[int(t.Month())-1] } - return string([]rune(monthNamesSlovenian[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSlovenian[(t.Month() - 1)])[:1]) } // localMonthsNameSomali returns the Somali name of the month. func localMonthsNameSomali(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSomaliAbbr[int(t.Month()-1)] + return monthNamesSomaliAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSomali[int(t.Month())-1] } - return string([]rune(monthNamesSomali[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSomali[(t.Month() - 1)])[:1]) } // localMonthsNameSotho returns the Sotho name of the month. func localMonthsNameSotho(t time.Time, abbr int) string { if abbr == 3 { - return monthNamesSothoAbbr[int(t.Month()-1)] + return monthNamesSothoAbbr[(t.Month() - 1)] } if abbr == 4 || abbr > 6 { return monthNamesSotho[int(t.Month())-1] } - return string([]rune(monthNamesSotho[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSotho[(t.Month() - 1)])[:1]) } // localMonthsNameSpanish returns the Spanish name of the month. @@ -6478,7 +6478,7 @@ func localMonthsNameSyriac(t time.Time, abbr int) string { if abbr == 4 { return monthNamesSyriac[int(t.Month())-1] } - return string([]rune(monthNamesSyriac[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesSyriac[(t.Month() - 1)])[:1]) } // localMonthsNameTajik returns the Tajik name of the month. @@ -6489,7 +6489,7 @@ func localMonthsNameTajik(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTajik[int(t.Month())-1] } - return string([]rune(monthNamesTajik[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTajik[(t.Month() - 1)])[:1]) } // localMonthsNameTamazight returns the Tamazight name of the month. @@ -6500,13 +6500,13 @@ func localMonthsNameTamazight(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTamazight[int(t.Month())-1] } - return string([]rune(monthNamesTamazight[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTamazight[(t.Month() - 1)])[:1]) } // localMonthsNameTamil returns the Tamil name of the month. func localMonthsNameTamil(t time.Time, abbr int) string { if abbr == 5 { - return string([]rune(monthNamesTamil[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTamil[(t.Month() - 1)])[:1]) } return monthNamesTamil[int(t.Month())-1] } @@ -6519,7 +6519,7 @@ func localMonthsNameTamilLK(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTamil[int(t.Month())-1] } - return string([]rune(monthNamesTamil[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTamil[(t.Month() - 1)])[:1]) } // localMonthsNameTatar returns the Tatar name of the month. @@ -6530,7 +6530,7 @@ func localMonthsNameTatar(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTatar[int(t.Month())-1] } - return string([]rune(monthNamesTatar[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTatar[(t.Month() - 1)])[:1]) } // localMonthsNameTelugu returns the Telugu name of the month. @@ -6541,7 +6541,7 @@ func localMonthsNameTelugu(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTelugu[int(t.Month())-1] } - return string([]rune(monthNamesTelugu[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTelugu[(t.Month() - 1)])[:1]) } // localMonthsNameSyllabics returns the Syllabics name of the month. @@ -6589,7 +6589,7 @@ func localMonthsNameTigrinya(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTigrinya[int(t.Month())-1] } - return string([]rune(monthNamesTigrinya[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTigrinya[(t.Month() - 1)])[:1]) } // localMonthsNameTsonga returns the Tsonga name of the month. @@ -6600,7 +6600,7 @@ func localMonthsNameTsonga(t time.Time, abbr int) string { if abbr == 4 { return monthNamesTsonga[int(t.Month())-1] } - return string([]rune(monthNamesTsonga[int(t.Month()-1)])[:1]) + return string([]rune(monthNamesTsonga[(t.Month() - 1)])[:1]) } // localMonthsNameTraditionalMongolian returns the Traditional Mongolian name of @@ -6922,10 +6922,10 @@ func (nf *numberFormat) daysHandler(token nfp.Token) { } if strings.Contains(strings.ToUpper(token.TValue), "A") { if l == 3 { - nf.result += weekdayNamesAbbr[int(nf.t.Weekday())] + nf.result += weekdayNamesAbbr[nf.t.Weekday()] } if l > 3 { - nf.result += weekdayNames[int(nf.t.Weekday())] + nf.result += weekdayNames[nf.t.Weekday()] } return } @@ -6936,9 +6936,9 @@ func (nf *numberFormat) daysHandler(token nfp.Token) { case 2: nf.result += fmt.Sprintf("%02d", nf.t.Day()) case 3: - nf.result += weekdayNamesAbbr[int(nf.t.Weekday())] + nf.result += weekdayNamesAbbr[nf.t.Weekday()] default: - nf.result += weekdayNames[int(nf.t.Weekday())] + nf.result += weekdayNames[nf.t.Weekday()] } } } diff --git a/rows.go b/rows.go index 7541a0b..878c8d8 100644 --- a/rows.go +++ b/rows.go @@ -63,7 +63,7 @@ func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) { return nil, err } rows, _ := f.Rows(sheet) - results, cur, max := make([][]string, 0, 64), 0, 0 + results, cur, maxVal := make([][]string, 0, 64), 0, 0 for rows.Next() { cur++ row, err := rows.Columns(opts...) @@ -72,10 +72,10 @@ func (f *File) GetRows(sheet string, opts ...Options) ([][]string, error) { } results = append(results, row) if len(row) > 0 { - max = cur + maxVal = cur } } - return results[:max], rows.Close() + return results[:maxVal], rows.Close() } // Rows defines an iterator to a sheet. diff --git a/stream.go b/stream.go index 8fbbcfd..ef7fa13 100644 --- a/stream.go +++ b/stream.go @@ -439,24 +439,24 @@ func (sw *StreamWriter) SetRow(cell string, values []interface{}, opts ...RowOpt // the width column B:C as 20: // // err := sw.SetColWidth(2, 3, 20) -func (sw *StreamWriter) SetColWidth(min, max int, width float64) error { +func (sw *StreamWriter) SetColWidth(minVal, maxVal int, width float64) error { if sw.sheetWritten { return ErrStreamSetColWidth } - if min < MinColumns || min > MaxColumns || max < MinColumns || max > MaxColumns { + if minVal < MinColumns || minVal > MaxColumns || maxVal < MinColumns || maxVal > MaxColumns { return ErrColumnNumber } if width > MaxColumnWidth { return ErrColumnWidth } - if min > max { - min, max = max, min + if minVal > maxVal { + minVal, maxVal = maxVal, minVal } sw.cols.WriteString(`