cellResolver calc cell value by given worksheet name, cell reference and context.
(ctx *calcContext, sheet, cell string)
| 1654 | |
| 1655 | // cellResolver calc cell value by given worksheet name, cell reference and context. |
| 1656 | func (f *File) cellResolver(ctx *calcContext, sheet, cell string) (formulaArg, error) { |
| 1657 | var ( |
| 1658 | arg formulaArg |
| 1659 | value string |
| 1660 | err error |
| 1661 | ) |
| 1662 | ref := sheet + "!" + cell |
| 1663 | if cached, ok := f.formulaArgCache.Load(ref); ok { |
| 1664 | return cached.(formulaArg), err |
| 1665 | } |
| 1666 | |
| 1667 | if formula, _ := f.getCellFormula(sheet, cell, true); len(formula) != 0 { |
| 1668 | ctx.mu.Lock() |
| 1669 | if ctx.entry != ref { |
| 1670 | if ctx.iterations[ref] <= f.options.MaxCalcIterations { |
| 1671 | ctx.iterations[ref]++ |
| 1672 | ctx.mu.Unlock() |
| 1673 | arg, _ = f.calcCellValue(ctx, sheet, cell) |
| 1674 | ctx.iterationsCache[ref] = arg |
| 1675 | f.formulaArgCache.Store(ref, arg) |
| 1676 | return arg, nil |
| 1677 | } |
| 1678 | ctx.mu.Unlock() |
| 1679 | return ctx.iterationsCache[ref], nil |
| 1680 | } |
| 1681 | ctx.mu.Unlock() |
| 1682 | } |
| 1683 | if value, err = f.GetCellValue(sheet, cell, Options{RawCellValue: true}); err != nil { |
| 1684 | return arg, err |
| 1685 | } |
| 1686 | arg = newStringFormulaArg(value) |
| 1687 | cellType, _ := f.GetCellType(sheet, cell) |
| 1688 | switch cellType { |
| 1689 | case CellTypeBool: |
| 1690 | arg = arg.ToBool() |
| 1691 | case CellTypeNumber, CellTypeUnset: |
| 1692 | if arg.Value() == "" { |
| 1693 | arg = newEmptyFormulaArg() |
| 1694 | } else { |
| 1695 | arg = arg.ToNumber() |
| 1696 | } |
| 1697 | case CellTypeInlineString, CellTypeSharedString: |
| 1698 | case CellTypeFormula: |
| 1699 | if value == "" { |
| 1700 | arg = newEmptyFormulaArg() |
| 1701 | } |
| 1702 | case CellTypeDate: |
| 1703 | if value, err = f.GetCellValue(sheet, cell); err == nil { |
| 1704 | if num := newStringFormulaArg(value).ToNumber(); num.Type == ArgNumber { |
| 1705 | arg = num |
| 1706 | } |
| 1707 | } |
| 1708 | default: |
| 1709 | arg = newErrorFormulaArg(value, value) |
| 1710 | } |
| 1711 | f.formulaArgCache.Store(ref, arg) |
| 1712 | return arg, err |
| 1713 | } |
no test coverage detected