MCPcopy
hub / github.com/qax-os/excelize / setArrayFormula

Method setArrayFormula

cell.go:840–870  ·  view source on GitHub ↗

setArrayFormula transform the array formula in an array formula range to the normal formula and set cells in this range to the formula as the normal formula.

(sheet string, formula *xlsxF, definedNames []DefinedName)

Source from the content-addressed store, hash-verified

838// normal formula and set cells in this range to the formula as the normal
839// formula.
840func (ws *xlsxWorksheet) setArrayFormula(sheet string, formula *xlsxF, definedNames []DefinedName) error {
841 if len(strings.Split(formula.Ref, ":")) < 2 {
842 return nil
843 }
844 coordinates, err := rangeRefToCoordinates(formula.Ref)
845 if err != nil {
846 return err
847 }
848 _ = sortCoordinates(coordinates)
849 tokens, arrayFormulaOperandTokens, err := getArrayFormulaTokens(sheet, formula.Content, definedNames)
850 if err != nil {
851 return err
852 }
853 topLeftCol, topLeftRow := coordinates[0], coordinates[1]
854 for c := coordinates[0]; c <= coordinates[2]; c++ {
855 for r := coordinates[1]; r <= coordinates[3]; r++ {
856 colOffset, rowOffset := c-topLeftCol, r-topLeftRow
857 for i, af := range arrayFormulaOperandTokens {
858 colNum, rowNum := af.topLeftCol+colOffset, af.topLeftRow+rowOffset
859 if colNum <= af.bottomRightCol && rowNum <= af.bottomRightRow {
860 arrayFormulaOperandTokens[i].targetCellRef, _ = CoordinatesToCellName(colNum, rowNum)
861 }
862 }
863 ws.prepareSheetXML(c, r)
864 if cell := &ws.SheetData.Row[r-1].C[c-1]; cell.f == "" {
865 cell.f = transformArrayFormula(tokens, arrayFormulaOperandTokens)
866 }
867 }
868 }
869 return err
870}
871
872// setArrayFormulaCells transform the array formula in all worksheets to the
873// normal formula and set cells in the array formula reference range to the

Callers 2

SetCellFormulaMethod · 0.80
setArrayFormulaCellsMethod · 0.80

Calls 6

prepareSheetXMLMethod · 0.95
rangeRefToCoordinatesFunction · 0.85
sortCoordinatesFunction · 0.85
getArrayFormulaTokensFunction · 0.85
CoordinatesToCellNameFunction · 0.85
transformArrayFormulaFunction · 0.85

Tested by

no test coverage detected