forked from plandem/xlsx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sheet.go
91 lines (84 loc) · 3.67 KB
/
sheet.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright (c) 2017 Andrey Gayvoronsky <[email protected]>
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package xlsx
import (
"github.com/plandem/xlsx/format/conditional"
"github.com/plandem/xlsx/types"
"github.com/plandem/xlsx/types/options/sheet"
)
const errorNotSupported = "not supported"
const errorNotSupportedWrite = "not supported in read-only mode"
const errorNotSupportedStream = "not supported in stream mode"
type SheetMode byte
//List of all possible open modes for Sheet. Mode applies only once, except SheetModeStream and few modes can be combined. E.g.: SheetModeStream, SheetModeMultiPhase
const (
sheetModeUnknown SheetMode = 0
sheetModeRead SheetMode = 1 << iota
sheetModeWrite
SheetModeStream //In stream mode only forward reading/writing is allowed
SheetModeMultiPhase //Sheet will be iterated two times: first one to load meta information (e.g. merged cells) and another one for sheet data. Only for SheetModeStream mode.
SheetModeIgnoreDimension //Ignore dimension information during reading or skip it during writing
)
//Sheet is interface for a higher level object that wraps ml.Worksheet with functionality
type Sheet interface {
//Cell returns a cell for 0-based indexes
Cell(colIndex, rowIndex int) *Cell
//CellByRef returns a cell for ref
CellByRef(cellRef types.CellRef) *Cell
//Rows returns iterator for all rows of sheet
Rows() RowIterator
//Row returns a row for 0-based index
Row(index int) *Row
//Cols returns iterator for all cols of sheet
Cols() ColIterator
//Col returns a col for 0-based index
Col(index int) *Col
//Range returns a range for indexes
Range(fromCol, fromRow, toCol, toRow int) *Range
//RangeByRef returns a range for ref
RangeByRef(ref types.Ref) *Range
//Dimension returns total number of cols and rows in sheet
Dimension() (cols int, rows int)
//SetDimension sets total number of cols and rows in sheet
SetDimension(cols, rows int)
//InsertRow inserts a row at 0-based index and returns it. Using to insert a row between other rows.
InsertRow(index int) *Row
//DeleteRow deletes a row at 0-based index
DeleteRow(index int)
//InsertCol inserts a col at 0-based index and returns it. Using to insert a col between other cols.
InsertCol(index int) *Col
//DeleteCol deletes a col at 0-based index
DeleteCol(index int)
//MergeRows merges rows between 0-based fromIndex and toIndex
MergeRows(fromIndex, toIndex int) error
//MergeCols merges cols between 0-based fromIndex and toIndex
MergeCols(fromIndex, toIndex int) error
//SplitRows splits rows between 0-based fromIndex and toIndex
SplitRows(fromIndex, toIndex int)
//SplitCols splits cols between 0-based fromIndex and toIndex
SplitCols(fromIndex, toIndex int)
//AddConditional adds conditional formatting to sheet, with additional refs if required
AddConditional(conditional *conditional.Info, refs ...types.Ref) error
//DeleteConditional deletes conditional formatting for refs
DeleteConditional(refs ...types.Ref)
//AutoFilter adds auto filter in provided Ref range with additional settings if required
AutoFilter(ref types.Ref, settings ...interface{})
//AddFilter adds a custom filter to column with 0-based colIndex
AddFilter(colIndex int, settings ...interface{}) error
//DeleteFilter deletes a filter from column with 0-based colIndex
DeleteFilter(colIndex int)
//Name returns name of sheet
Name() string
//SetName sets a name for sheet
SetName(name string)
//Set sets options for sheet
SetOptions(o *options.Info)
//SetActive sets the sheet as active
SetActive()
//Close frees allocated by sheet resources
Close()
//private methods to use by internals only
mode() SheetMode
info() *sheetInfo
}