Documentation ¶
Index ¶
- Constants
- type Cell
- type CellAddress
- type Expression
- type Sheet
- func (s *Sheet) ContentAt(addr string) (string, error)
- func (s *Sheet) EditAt(addr string) (string, error)
- func (s *Sheet) MaxAddr() CellAddress
- func (s *Sheet) MaxCol() CellAddress
- func (s *Sheet) MaxRow() uint32
- func (s *Sheet) Read(r io.Reader) error
- func (s *Sheet) SetContent(addr string, content string) error
- func (s *Sheet) ValueAt(addr string) (float64, error)
- func (s *Sheet) WriteCSV(w io.Writer)
- func (s *Sheet) WriteCSV2(w io.Writer, headers, edit bool)
- func (s *Sheet) WriteRange(start CellAddress, end CellAddress, w io.Writer) error
Constants ¶
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cell ¶
type Cell struct {
// contains filtered or unexported fields
}
Cell is the basic unit of storage and computation for a spreadsheet. A Cell has an address and can store numbers, text, or compute its value based on an equation, consuming values from other Cells.
func NewCell ¶
func NewCell(a CellAddress, s *Sheet) *Cell
Create a new cell at CellAddress a in Sheet s
func (*Cell) Content ¶
Content returns a string representation of the value of the cell. This will be a string representation of a number if the cell is numeric or has as equation that returns a result. It will be an error message if an equation results in an error, or it will be a string if text was entered into the cell.
func (*Cell) EditValue ¶
EditValue returns the value to show when "editing" the cell. This means it will return the string, value or equation that is in the cell and not return the evaluated result of an equation.
func (*Cell) Recalculate ¶
func (c *Cell) Recalculate()
Recalculate recalculates the value of this cell and any downstream cells that would be affected by this cell's value. It will detect any dependency cycles present and set error messages on the affected cells.
func (*Cell) SetContent ¶
SetContent puts some value into the Cell, c. SetContent detects whether an equation, number, or text was entered and recalculates the sheet accordingly.
type CellAddress ¶
type CellAddress struct {
// contains filtered or unexported fields
}
CellAddress is the address of a cell in a sheet.
func CellAddr ¶
func CellAddr(addr string) (CellAddress, error)
CellAddr creates a new CellAddress by parsing an address string, addr. addr must be of the format [A-Za-z]+[0-9]+, where the alphabetic characters are the column and the number is the row, as in a traditional spreadsheet. Currently, an most 2 alphabetic characters are specified for a maximum of 26^2 (676) columns. The number of rows is bounded to math.MaxUint32.
func NewCellAddr ¶ added in v0.2.0
func NewCellAddr(col string, row uint32) (CellAddress, error)
func (CellAddress) Column ¶ added in v0.2.0
func (ca CellAddress) Column() string
Column returns the alphabetical column of the Cell.
func (CellAddress) LEQCol ¶
func (ca CellAddress) LEQCol(ca2 CellAddress) bool
LEQCol returns true if ca's column is less or equal to ca2's column.
func (CellAddress) LessCol ¶
func (ca CellAddress) LessCol(ca2 CellAddress) bool
LessCol returns true if ca's column is strictly less than ca2's column.
func (CellAddress) NextCol ¶
func (ca CellAddress) NextCol() (CellAddress, error)
NextCol returns the next column after ca's column. It returns error if ca has the last column possible.
func (CellAddress) Row ¶ added in v0.2.0
func (ca CellAddress) Row() uint32
Row returns the numeric row of the Cell.
func (CellAddress) String ¶
func (ca CellAddress) String() string
String returns a human-readable representation of ca. This value can also be parsed by CellAddr.
type Expression ¶
type Expression struct {
// contains filtered or unexported fields
}
Expression is an equation that can be evaluated on a Sheet.
func ParseExpression ¶
func ParseExpression(eqn string) (*Expression, error)
ID = '[a-zA-Z0-9]+' ADD = '+' SUB = '-' MUL = '*' DIV = '/' LP = '(' RP = ')' OP = [+-*/]
type Sheet ¶
type Sheet struct { // OnCellUpdated is a callback that will be called when a cell is updated during // recalculations. It is *NOT* called when explicitly setting the content of a cell. // OnCellUpdated may be set by the user. OnCellUpdated func(addr string, c *Cell) // contains filtered or unexported fields }
Sheet represents a spreadsheet.
func (*Sheet) ContentAt ¶
ContentAt will return a human-readable value for a given address, suitable for display. This will display the result of any equation.
func (*Sheet) EditAt ¶
EditAt returns a human-readable representation of the value of the cell at address addr, suitable for editing. This means cells containing equations will return the equation text rather that the result of evaluating the equation.
func (*Sheet) MaxAddr ¶ added in v0.2.0
func (s *Sheet) MaxAddr() CellAddress
MaxAddr returns the highest (by row and column) CellAddress for a sheet. The highest address is defined by the highest row value in the sheet where the row contains a Cell with a value, and the highest column value where the column contains a value. The cell at CellAddress may not contain a value. Instead, can be thought of the bottom-right corner of the spreadsheet, where all cells with content are contained between A1 and s.MaxAddr().
func (*Sheet) MaxCol ¶ added in v0.2.0
func (s *Sheet) MaxCol() CellAddress
MaxCol returns the last column containing a cell with a value in the sheet.
func (*Sheet) MaxRow ¶ added in v0.2.0
MaxRow returns the highest number row containing a cell with a value in the sheet.
func (*Sheet) Read ¶
Read reads an instruction (such as those written by WriteRange) and sets the value in the sheet. Instructions are in the form:
[address] value\n
For example, you can set various fields in the sheet by doing the following:
A1 10 B1 20 C1 30 D1 =A1+B1+C1
func (*Sheet) SetContent ¶
SetContent sets the content of the cell at address addr in the sheet. If the address is invalid, SetContent returns an error.
func (*Sheet) ValueAt ¶
ValueAt returns the numeric value present at address addr in s. If the addr is invalid or there is not a numeric value available at addr, ValueAt returns an error. Empty cells have an implicit numeric value of 0.
func (*Sheet) WriteCSV ¶
WriteCSV writes out a CSV containing the contents of the sheet. This uses the ContentAt function to write human-readable values of the cells, including the results of the evaluated equations.
func (*Sheet) WriteRange ¶
func (s *Sheet) WriteRange(start CellAddress, end CellAddress, w io.Writer) error
WriteRange writes instructions to recreate the cells between the upper left start and bottom right end cells to w. The stream written is human-readable and suitable for reading with (*Sheet).Read