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

Method rangeResolver

calc.go:1718–1815  ·  view source on GitHub ↗

rangeResolver extract value as string from given reference and range list. This function will not ignore the empty cell. For example, A1:A2:A2:B3 will be reference A1:B3.

(ctx *calcContext, cellRefs, cellRanges *list.List)

Source from the content-addressed store, hash-verified

1716// This function will not ignore the empty cell. For example, A1:A2:A2:B3 will
1717// be reference A1:B3.
1718func (f *File) rangeResolver(ctx *calcContext, cellRefs, cellRanges *list.List) (arg formulaArg, err error) {
1719 arg.cellRefs, arg.cellRanges = cellRefs, cellRanges
1720 // value range order: from row, to row, from column, to column
1721 valueRange := []int{0, 0, 0, 0}
1722 var sheet string
1723 // prepare value range
1724 for temp := cellRanges.Front(); temp != nil; temp = temp.Next() {
1725 cr := temp.Value.(cellRange)
1726 rng := []int{cr.From.Col, cr.From.Row, cr.To.Col, cr.To.Row}
1727 _ = sortCoordinates(rng)
1728 cr.From.Col, cr.From.Row, cr.To.Col, cr.To.Row = rng[0], rng[1], rng[2], rng[3]
1729 prepareValueRange(cr, valueRange)
1730 if cr.From.Sheet != "" {
1731 sheet = cr.From.Sheet
1732 }
1733 }
1734 for temp := cellRefs.Front(); temp != nil; temp = temp.Next() {
1735 cr := temp.Value.(cellRef)
1736 if cr.Sheet != "" {
1737 sheet = cr.Sheet
1738 }
1739 prepareValueRef(cr, valueRange)
1740 }
1741 // extract value from ranges
1742 if cellRanges.Len() > 0 {
1743 arg.Type = ArgMatrix
1744
1745 var ws *xlsxWorksheet
1746 ws, err = f.workSheetReader(sheet)
1747 if err != nil {
1748 return
1749 }
1750
1751 // Detect whole column/row reference, limit to actual data range
1752 if valueRange[1] == TotalRows {
1753 actualMaxRow := 0
1754 for _, rowData := range ws.SheetData.Row {
1755 if rowData.R > actualMaxRow {
1756 actualMaxRow = rowData.R
1757 }
1758 }
1759 if actualMaxRow > 0 && actualMaxRow < TotalRows {
1760 valueRange[1] = actualMaxRow
1761 }
1762 }
1763 if valueRange[3] == MaxColumns {
1764 actualMaxCol := 0
1765 for _, rowData := range ws.SheetData.Row {
1766 for _, cell := range rowData.C {
1767 col, _, err := CellNameToCoordinates(cell.R)
1768 if err == nil && col > actualMaxCol {
1769 actualMaxCol = col
1770 }
1771 }
1772 }
1773 if actualMaxCol > 0 && actualMaxCol < MaxColumns {
1774 valueRange[3] = actualMaxCol
1775 }

Callers 2

parseReferenceMethod · 0.95
TestCalcRangeResolverFunction · 0.95

Calls 10

workSheetReaderMethod · 0.95
cellResolverMethod · 0.95
sortCoordinatesFunction · 0.85
prepareValueRangeFunction · 0.85
prepareValueRefFunction · 0.85
CellNameToCoordinatesFunction · 0.85
newEmptyFormulaArgFunction · 0.85
CoordinatesToCellNameFunction · 0.85
LenMethod · 0.80
NextMethod · 0.45

Tested by 1

TestCalcRangeResolverFunction · 0.76