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)
| 838 | // normal formula and set cells in this range to the formula as the normal |
| 839 | // formula. |
| 840 | func (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 |
no test coverage detected