Ejemplo n.º 1
0
Archivo: cell.go Proyecto: howeyc/sc
// Returns the value to display as a string. This is the value that shows up on
// cell in the sheet display. This is the result of any calculation that may have
// been required to be performed.
//
// Cell is assumed not to be string type when this function is called.
func (c *Cell) getDisplayValue(s *Sheet, address Address) string {
	postfix := evaler.GetPostfix(c.value)
	for idx, token := range postfix {
		if evaler.IsCellAddr(token) {
			refCellVal := ""
			if cell, err := s.GetCell(Address(token)); err == nil {
				refCellVal = cell.getDisplayValue(s, Address(token))
			}
			postfix[idx] = refCellVal
		}
	}
	if rat, err := evaler.EvaluatePostfix(postfix); err == nil {
		return rat.FloatString(s.getPrecision(address))
	} else {
		return ""
	}
}
Ejemplo n.º 2
0
Archivo: sheet.go Proyecto: howeyc/sc
// Sets the address to the passed in cell. Previous cell data that exists is thrown away.
func (s *Sheet) SetCell(address Address, cell *Cell) {
	if currentCell, found := s.data[address]; found {
		cell.backRefs = currentCell.backRefs
	}
	if !cell.stringType {
		postfix := evaler.GetPostfix(cell.value)
		for _, token := range postfix {
			if evaler.IsCellAddr(token) {
				tokenAddr := Address(token)
				cell.forwardRefs[tokenAddr] = struct{}{}
				if tokCell, tokErr := s.GetCell(tokenAddr); tokErr == nil {
					tokCell.backRefs[address] = struct{}{}
				}
			}
		}
	}
	s.data[address] = cell

	s.setMaximums(address)

	// TODO: change to display current cell and all back references
	s.display()
}