Fixes locking for relative reference and adds range relative reference
This commit is contained in:
parent
73d1829053
commit
edc9fa50b6
|
@ -194,6 +194,10 @@ The number stack can be manipulated in a number of ways. You have seem mathemati
|
|||
|
||||
`OVER` will copy the number underneath the top value on the stack and place the copy on the top of the stack without removing any numbers from the stack..
|
||||
|
||||
#### Ranges
|
||||
|
||||
_tally_ can accept ranges of cells for operation. However, _tally_ currently only supports summing the numerical values of those cells. The syntax is `A1:B3+`. The `+` at the end designates summing the range. Eventually there may be other range operations available. Locking rows and columns _can_ be used in ranges.
|
||||
|
||||
#### Errors
|
||||
|
||||
If there is a problem in your expression, the cell will report `#Err`, likely followed by a message about the nature of the problem. If you try to reference a stack value that doesn't exist, for example... or even a cell that does not exist.
|
||||
|
|
8
main.go
8
main.go
|
@ -152,9 +152,15 @@ func Addr2Point(addr string) (point, bool, bool) {
|
|||
return p, lockRow, lockCol
|
||||
}
|
||||
|
||||
func Point2Addr(p point) string {
|
||||
func Point2Addr(p point, lockRow, lockCol bool) string {
|
||||
var s strings.Builder
|
||||
if lockCol {
|
||||
s.WriteRune('$')
|
||||
}
|
||||
s.WriteRune(rune(p.col) + 65)
|
||||
if lockRow {
|
||||
s.WriteRune('$')
|
||||
}
|
||||
s.WriteString(strconv.Itoa(p.row+1))
|
||||
return s.String()
|
||||
}
|
||||
|
|
23
sheet.go
23
sheet.go
|
@ -141,8 +141,29 @@ func (s *sheet) PasteRelative() {
|
|||
if !lockCol {
|
||||
diffApply.col = refPoint.col-diff.col
|
||||
}
|
||||
p2a := Point2Addr(diffApply)
|
||||
p2a := Point2Addr(diffApply, lockRow, lockCol)
|
||||
c.expr[i] = p2a
|
||||
} else if IsRange(v) {
|
||||
op := v[len(v)-1]
|
||||
points := strings.Split(v[:len(v)-1], ":")
|
||||
startRefPoint, lockStartRow, lockStartCol := Addr2Point(points[0])
|
||||
endRefPoint, lockEndRow, lockEndCol := Addr2Point(points[1])
|
||||
diff := point{row: s.yankPoint.row-s.selection.row+1, col: s.yankPoint.col-s.selection.col+1}
|
||||
startApply := point{row: startRefPoint.row, col: startRefPoint.col}
|
||||
endApply := point{row: endRefPoint.row, col: endRefPoint.col}
|
||||
if !lockStartRow {
|
||||
startApply.row = startRefPoint.row-diff.row
|
||||
}
|
||||
if !lockStartCol {
|
||||
startApply.col = startRefPoint.col-diff.col
|
||||
}
|
||||
if !lockEndRow {
|
||||
endApply.row = endRefPoint.row-diff.row
|
||||
}
|
||||
if !lockEndCol {
|
||||
endApply.col = endRefPoint.col-diff.col
|
||||
}
|
||||
c.expr[i] = fmt.Sprintf("%s:%s%c", Point2Addr(startApply, lockStartRow, lockStartCol), Point2Addr(endApply, lockEndRow, lockEndCol), op)
|
||||
}
|
||||
}
|
||||
c.rawVal = strings.Join(c.expr, " ")
|
||||
|
|
Loading…
Reference in New Issue