forked from tealeg/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cellstore.go
63 lines (55 loc) · 2.38 KB
/
cellstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package xlsx
import "fmt"
// CellStore provides an interface for interacting with backend cell
// storage. For example, this allows us, as required, to persist cells
// to some store instead of holding them in memory. This tactic
// allows us a degree of control around the characteristics of our
// programs when handling large spreadsheets - we can choose to run
// more slowly, but without exhausting system memory.
//
// If you wish to implement a custom CellStore you must not only
// support this interface, but also a CellStoreConstructor and a
// FileOption that set's the File's cellStoreConstructor to the right
// constructor.
type CellStore interface {
MakeRow(sheet *Sheet) *Row
MakeRowWithLen(sheet *Sheet, len int) *Row
ReadRow(key string, sheet *Sheet) (*Row, error)
WriteRow(r *Row) error
MoveRow(r *Row, newIndex int) error
RemoveRow(key string) error
Close() error
}
// CellStoreConstructor defines the signature of a function that will
// be used to return a new instance of the CellStore implmentation,
// you must pass this into
type CellStoreConstructor func() (CellStore, error)
// CellStoreRow is the interface used to interact with the currently loaded Row from the CellStore. Different backends can choose whether to hold the whole row in memory, or persist and load the cell
type CellStoreRow interface {
AddCell() *Cell
GetCell(colIdx int) *Cell
PushCell(c *Cell)
ForEachCell(cvf CellVisitorFunc, option ...CellVisitorOption) error
MaxCol() int
CellCount() int
Updatable()
CellUpdatable(c *Cell)
}
// CellVisitorFunc defines the signature of a function that will be
// called when visiting a Cell using CellStore.ForEachInRow.
type CellVisitorFunc func(c *Cell) error
// RowNotFoundError is an Error that should be returned by a
// RowStore implementation if a call to ReadRow is made with a key
// that doesn't correspond to any persisted Row.
type RowNotFoundError struct {
key string
reason string
}
// NewRowNotFoundError creates a new RowNotFoundError, capturing the Row key and the reason this key could not be found.
func NewRowNotFoundError(key, reason string) *RowNotFoundError {
return &RowNotFoundError{key, reason}
}
// Error returns a human-readable description of the failure to find a Row. It makes RowNotFoundError comply with the Error interface.
func (cnfe RowNotFoundError) Error() string {
return fmt.Sprintf("Row %q not found. %s", cnfe.key, cnfe.reason)
}