Documentation
¶
Index ¶
- Constants
- func ExtractFromCell(cell string, line int) string
- func MetabookOptions() *tableaupb.WorkbookOptions
- func MetasheetOptions(context context.Context) *tableaupb.WorksheetOptions
- type Book
- func (b *Book) AddSheet(sheet *Sheet)
- func (b *Book) BookName() string
- func (b *Book) Clear()
- func (b *Book) DelSheet(sheetName string)
- func (b *Book) ExportCSV() error
- func (b *Book) ExportExcel() error
- func (b *Book) Filename() string
- func (b *Book) Format() format.Format
- func (b *Book) GetBookOptions() *tableaupb.WorkbookOptions
- func (b *Book) GetSheet(name string) *Sheet
- func (b *Book) GetSheets() []*Sheet
- func (b *Book) ParseMetaAndPurge() (err error)
- func (b *Book) Squeeze(sheetNames []string)
- func (b *Book) String() string
- type Cell
- type Column
- type ColumnLookupTable
- type Kind
- type Node
- func (n *Node) DebugKV() []any
- func (n *Node) DebugNameKV() []any
- func (n *Node) DebugValueKV() []any
- func (n *Node) FindChild(name string) *Node
- func (n *Node) GetChildrenWithoutMeta() (nodes []*Node)
- func (n *Node) GetDataSheetName() string
- func (n *Node) GetMetaIncell() bool
- func (n *Node) GetMetaKey() string
- func (n *Node) GetMetaKeyNode() *Node
- func (n *Node) GetMetaSheet() string
- func (n *Node) GetMetaStructNode() *Node
- func (n *Node) GetMetaType() string
- func (n *Node) GetMetaTypeNode() *Node
- func (n *Node) GetMetaVariable() string
- func (n *Node) GetValue() string
- func (n *Node) IsMeta() bool
- func (n *Node) ScalarValue() string
- func (n *Node) String() string
- func (n *Node) StructNode() *Node
- type Position
- type Row
- type Sheet
- func (s *Sheet) GetDataName() string
- func (s *Sheet) GetDebugName() string
- func (s *Sheet) GetProtoName() string
- func (s *Sheet) ParseMetasheet(parser SheetParser) (*internalpb.Metabook, error)
- func (s *Sheet) String() string
- func (s *Sheet) SubTableSheet(options ...TableOption) *Sheet
- func (s *Sheet) Tabler() Tabler
- func (s *Sheet) ToWorkseet() *internalpb.Worksheet
- type SheetParser
- type Table
- func (t *Table) BeginCol() int
- func (t *Table) BeginRow() int
- func (t *Table) Cell(row, col int) (string, error)
- func (t *Table) ColSize() int
- func (t *Table) EndCol() int
- func (t *Table) EndRow() int
- func (t *Table) ExportCSV(writer io.Writer) error
- func (t *Table) ExportExcel(file *excelize.File, sheetName string) error
- func (t *Table) FindBlockEndRow(startRow int) int
- func (t *Table) GetRow(row int) []string
- func (t *Table) Position(row, col int) string
- func (t *Table) RowSize() int
- func (t *Table) String() string
- func (t *Table) SubTable(options ...TableOption) *Table
- func (t *Table) Transpose() *TransposedTable
- type TableOption
- type TableOptions
- type Tabler
- type TransposedTable
- func (t *TransposedTable) BeginCol() int
- func (t *TransposedTable) BeginRow() int
- func (t *TransposedTable) Cell(row, col int) (string, error)
- func (t *TransposedTable) ColSize() int
- func (t *TransposedTable) EndCol() int
- func (t *TransposedTable) EndRow() int
- func (t *TransposedTable) FindBlockEndRow(startRow int) int
- func (t *TransposedTable) GetRow(row int) []string
- func (t *TransposedTable) Position(row, col int) string
- func (t *TransposedTable) RowSize() int
- func (t *TransposedTable) SubTable(options ...TableOption) *Table
Constants ¶
const ( KeywordSheet = "@sheet" KeywordType = "@type" KeywordStruct = "@struct" KeywordKey = types.DefaultDocumentMapKeyOptName // @key KeywordValue = types.DefaultDocumentMapValueOptName // @value KeywordIncell = "@incell" KeywordVariable = "@variable" KeywordNote = "@note" )
const BookNameInMetasheet = "#"
BookNameInMetasheet is the special sign which represents workbook itself in metasheet. Default is "#".
const MacroIgnore = "#IGNORE" // bool: whether to ignore row
Macro command definitions
const MetaSign = "@"
MetaSign signifies the name starts with leading "@" is meta name.
const SheetKey = "@sheet"
Variables ¶
This section is empty.
Functions ¶
func ExtractFromCell ¶
func MetabookOptions ¶ added in v0.13.0
func MetabookOptions() *tableaupb.WorkbookOptions
func MetasheetOptions ¶ added in v0.9.12
func MetasheetOptions(context context.Context) *tableaupb.WorksheetOptions
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
func NewBook ¶
func NewBook(ctx context.Context, bookName, filename string, parser SheetParser) *Book
NewBook creates a new book. Example:
- bookName: Test
- filename: testdata/Test.xlsx
func (*Book) ExportExcel ¶
func (*Book) GetBookOptions ¶ added in v0.13.0
func (b *Book) GetBookOptions() *tableaupb.WorkbookOptions
GetBookOptions creates a new tableaupb.WorkbookOptions based on this special sheet(#)'s info.
func (*Book) ParseMetaAndPurge ¶ added in v0.10.7
ParseMetaAndPurge parses metasheet to Metabook and purge needless sheets which is not in parsed Metabook.
type ColumnLookupTable ¶ added in v0.10.7
column name -> column index (started with 0)
type Node ¶ added in v0.11.0
type Node struct {
Kind Kind
Name string
Value string
Children []*Node
// Line and Column hold the node position in the file.
NamePos Position
ValuePos Position
// Note is an optional comment attached to this node in the source
// document (e.g. YAML `#` line comment, XML `@note` attribute),
// extracted so that protogen can emit it as the generated proto
// field's comment.
Note string
}
Node represents an element in the tree document hierarchy.
References:
- https://pkg.go.dev/gopkg.in/yaml.v3?utm_source=godoc#Node
- https://pkg.go.dev/github.com/moovweb/gokogiri/xml#Node
func (*Node) DebugNameKV ¶ added in v0.11.0
func (*Node) DebugValueKV ¶ added in v0.11.0
func (*Node) GetChildrenWithoutMeta ¶ added in v0.11.0
GetChildrenWithoutMeta returns this node's children without meta nodes defined in schema sheet.
func (*Node) GetDataSheetName ¶ added in v0.11.0
GetDataSheetName returns original data sheet name by removing leading symbol "@" from meta sheet name.
e.g.: "@SheetName" -> "SheetName"
func (*Node) GetMetaIncell ¶ added in v0.11.0
GetMetaIncell returns this node's @incell defined in schema sheet.
func (*Node) GetMetaKey ¶ added in v0.11.0
GetMetaKey returns this node's key defined in schema sheet.
func (*Node) GetMetaKeyNode ¶ added in v0.16.2
GetMetaKeyNode returns the @key node of a vertical-map struct, or nil if the struct has no explicit key (e.g. an incell map). The @key node carries the key field's name as its Value, and may carry a Note extracted from the source document that should be attached to the generated key field.
func (*Node) GetMetaSheet ¶ added in v0.11.0
GetMetaSheet returns this node's @sheet defined in document node.
func (*Node) GetMetaStructNode ¶ added in v0.11.0
GetMetaStructNode returns this node's @struct node defined in schema sheet.
func (*Node) GetMetaType ¶ added in v0.11.0
GetMetaType returns this node's @type defined in schema sheet.
func (*Node) GetMetaTypeNode ¶ added in v0.11.0
GetMetaTypeNode returns this node's @type node defined in schema sheet.
func (*Node) GetMetaVariable ¶ added in v0.11.0
GetMetaVariable returns this node's variable name defined in schema sheet.
func (*Node) GetValue ¶ added in v0.11.0
GetValue returns node's value. It will return empty string if node is nil.
func (*Node) IsMeta ¶ added in v0.11.0
IsMeta checks whether this node is meta (name starts with leading "@") or not.
func (*Node) ScalarValue ¶ added in v0.14.0
ScalarValue returns node's value. XML importer will convert a scalar node to an 1-elem list node and this returns the elem's value as node's value.
func (*Node) String ¶ added in v0.11.0
String returns hierarchy representation of the Node, mainly for debugging.
func (*Node) StructNode ¶ added in v0.14.0
StructNode returns node's as a struct node. XML importer will convert a struct node to an 1-elem list node and this returns the elem node as struct node.
type Row ¶ added in v0.15.0
type Row struct {
Row int // row number
// contains filtered or unexported fields
}
Row represents a row in the sheet.
func NewRow ¶ added in v0.15.0
func NewRow(row int, prev *Row, lookupTable ColumnLookupTable) *Row
NewRow creates a new row.
func (*Row) CellDebugKV ¶ added in v0.15.0
CellDebugKV returns a list of key-value pairs for debugging.
func (*Row) GetCellCountWithPrefix ¶ added in v0.15.0
GetCellCountWithPrefix returns the cell count with the given prefix.
type Sheet ¶
type Sheet struct {
Name string
// Table represents the data structure of 2D flat table formats.
// E.g.: Excel, CSV.
Table *Table
// Document represents the data structure of tree document formats.
// E.g.: XML, YAML.
Document *Node
// Meta represents sheet's metadata, containing sheet’s layout,
// parser options, loader options, and so on.
Meta *internalpb.Metasheet
}
func NewDocumentSheet ¶ added in v0.11.0
NewDocumentSheet creates a new Sheet with a document.
func NewTableSheet ¶ added in v0.11.0
NewTableSheet creates a new Sheet with a table.
func (*Sheet) GetDataName ¶ added in v0.11.0
GetDataName returns original data sheet name by removing leading symbol "@" from meta sheet name. For example: "@SheetName" -> "SheetName".
func (*Sheet) GetDebugName ¶ added in v0.11.0
GetDebugName returns sheet name with alias if specified.
func (*Sheet) GetProtoName ¶ added in v0.11.0
GetDebugName returns this sheet's corresponding protobuf message name.
func (*Sheet) ParseMetasheet ¶ added in v0.11.0
func (s *Sheet) ParseMetasheet(parser SheetParser) (*internalpb.Metabook, error)
ParseMetasheet parses a sheet to Metabook by the specified parser.
func (*Sheet) String ¶
String returns the string representation of the Sheet, mainly for debugging.
- Table: CSV form
- Document: hierachy form
func (*Sheet) SubTableSheet ¶ added in v0.15.0
func (s *Sheet) SubTableSheet(options ...TableOption) *Sheet
SubTableSheet creates a new sub table sheet with the specified options.
func (*Sheet) Tabler ¶ added in v0.15.0
Tabler returns the table of the Sheet. If the sheet is not a table, returns nil. If the sheet is transposed, returns the transposed table, otherwise returns the original table.
func (*Sheet) ToWorkseet ¶ added in v0.11.0
func (s *Sheet) ToWorkseet() *internalpb.Worksheet
ToWorkseet creates a new basic internalpb.Worksheet without fields populated, based on this sheet's info.
type Table ¶ added in v0.11.0
type Table struct {
Rows [][]string // 2D array strings
// contains filtered or unexported fields
}
Table represents a 2D array table.
func (*Table) EndCol ¶ added in v0.14.0
EndCol returns the end column (column after the last column) of this table.
For loop example:
for col := t.BeginCol(); row < t.EndCol(); col++ {
fmt.Println(col)
}
func (*Table) EndRow ¶ added in v0.14.0
EndRow returns the end row (row after the last row) of this table.
For loop example:
for row := t.BeginRow(); row < t.EndRow(); row++ {
fmt.Println(row)
}
func (*Table) ExportExcel ¶ added in v0.11.0
ExportExcel exports Table to excel sheet.
func (*Table) FindBlockEndRow ¶ added in v0.12.0
FindBlockEndRow finds the end row (row after the last non-empty row) of the block. If the start row is empty, it will just return the start row. Otherwise, it will return past-the-last non-empty row.
NOTE: A block is a series of contiguous non-empty rows. So different blocks are seperated by one or more empty rows.
func (*Table) GetRow ¶ added in v0.11.0
GetRow returns the row data by row index (started with 0). It will return nil if not found.
func (*Table) Position ¶ added in v0.15.0
Position generate the position (row, col) (e.g.: A1) in a table.
NOTE: row and col are both 0-based.
func (*Table) String ¶ added in v0.11.0
String converts Table to CSV string. It is mainly used for debugging.
func (*Table) SubTable ¶ added in v0.15.0
func (t *Table) SubTable(options ...TableOption) *Table
SubTable creates a sub table of the table with specified options.
func (*Table) Transpose ¶ added in v0.15.0
func (t *Table) Transpose() *TransposedTable
Transpose interchanges the rows and columns of the table.
type TableOption ¶ added in v0.14.0
type TableOption func(*TableOptions)
TableOption is the functional option type for table.
func Cols ¶ added in v0.14.0
func Cols(begin, end int) TableOption
Cols sets the table-occupied column range of the whole sheet: [begin, end).
func Rows ¶ added in v0.14.0
func Rows(begin, end int) TableOption
Rows sets the table-occupied row range of the whole sheet: [begin, end).
type TableOptions ¶ added in v0.14.0
type Tabler ¶ added in v0.15.0
type Tabler interface {
// BeginRow returns the begin row of this table.
BeginRow() int
// EndRow returns the end row (row after the last row) of this table.
EndRow() int
// BeginCol returns the begin column of this table.
BeginCol() int
// EndCol returns the end column (column after the last column) of this table.
EndCol() int
// RowSize returns the row size of this table.
RowSize() int
// ColSize returns the column size of this table.
ColSize() int
// Cell returns the cell value at (row, col).
Cell(row, col int) (string, error)
// GetRow returns the row data by row index (started with 0). It will return
// nil if not found.
GetRow(row int) []string
// Position generate the position (row, col) (e.g.: A1) in a table.
//
// NOTE: row and col are both 0-based.
Position(row, col int) string
// FindBlockEndRow finds the end row (row after the last non-empty row) of
// the block. If the start row is empty, it will just return the start row.
// Otherwise, it will return past-the-last non-empty row.
//
// NOTE: A block is a series of contiguous non-empty rows. So different blocks
// are seperated by one or more empty rows.
FindBlockEndRow(startRow int) int
// SubTable creates a sub-table of the table with specified options.
SubTable(options ...TableOption) *Table
}
type TransposedTable ¶ added in v0.15.0
type TransposedTable struct {
// contains filtered or unexported fields
}
func (*TransposedTable) BeginCol ¶ added in v0.15.0
func (t *TransposedTable) BeginCol() int
func (*TransposedTable) BeginRow ¶ added in v0.15.0
func (t *TransposedTable) BeginRow() int
func (*TransposedTable) Cell ¶ added in v0.15.0
func (t *TransposedTable) Cell(row, col int) (string, error)
func (*TransposedTable) ColSize ¶ added in v0.15.0
func (t *TransposedTable) ColSize() int
func (*TransposedTable) EndCol ¶ added in v0.15.0
func (t *TransposedTable) EndCol() int
func (*TransposedTable) EndRow ¶ added in v0.15.0
func (t *TransposedTable) EndRow() int
func (*TransposedTable) FindBlockEndRow ¶ added in v0.15.0
func (t *TransposedTable) FindBlockEndRow(startRow int) int
func (*TransposedTable) GetRow ¶ added in v0.15.0
func (t *TransposedTable) GetRow(row int) []string
func (*TransposedTable) Position ¶ added in v0.15.0
func (t *TransposedTable) Position(row, col int) string
func (*TransposedTable) RowSize ¶ added in v0.15.0
func (t *TransposedTable) RowSize() int
func (*TransposedTable) SubTable ¶ added in v0.15.0
func (t *TransposedTable) SubTable(options ...TableOption) *Table