Documentation
¶
Index ¶
- Constants
- Variables
- func ExtractFromCell(cell string, line int32) string
- func MetasheetOptions() *tableaupb.WorksheetOptions
- func SetMetasheetName(name string)
- 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) GetSheet(name string) *Sheet
- func (b *Book) GetSheets() []*Sheet
- func (b *Book) Metabook() *internalpb.Metabook
- func (b *Book) ParseMetaAndPurge() (err error)
- func (b *Book) Squeeze(sheetNames []string)
- func (b *Book) String() string
- 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) GetMetaKeyname() string
- 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) String() string
- type Position
- type RowCell
- type RowCells
- func (r *RowCells) Cell(name string, optional bool) (*RowCell, error)
- func (r *RowCells) CellDebugKV(name string) []any
- func (rc *RowCells) Free()
- func (r *RowCells) GetCellCountWithPrefix(prefix string) int
- func (r *RowCells) NewCell(col int, name, typ *string, data string, needPopulateKey bool)
- func (r *RowCells) SetColumnLookupTable(table ColumnLookupTable)
- type Sheet
- type SheetParser
- type Table
- func (t *Table) Cell(row, col int) (string, error)
- func (t *Table) ExportCSV(writer io.Writer) error
- func (t *Table) ExportExcel(file *excelize.File, sheetName string) error
- func (t *Table) ExtractBlock(startRow int) (rows [][]string, endRow int)
- func (t *Table) FindBlockEndRow(startRow int) int
- func (t *Table) GetRow(row int) []string
- func (t *Table) IsRowEmpty(row int) bool
- func (t *Table) String() string
Constants ¶
const ( KeywordSheet = "@sheet" KeywordType = "@type" KeywordStruct = "@struct" KeywordKey = types.DefaultDocumentMapKeyOptName // @key KeywordValue = types.DefaultDocumentMapValueOptName // @value KeywordIncell = "@incell" KeywordVariable = "@variable" KeywordKeyname = "@keyname" )
const BookNameInMetasheet = "#"
BookNameInMetasheet is the special sign which represents workbook itself in metasheet. Default is "#".
const MetaSign = "@"
MetaSign signifies the name starts with leading "@" is meta name.
const SheetKey = "@sheet"
Variables ¶
var MetasheetName = "@TABLEAU"
MetasheetName is the name of metasheet which defines the metadata of each worksheet. Default is "@TABLEAU".
Functions ¶
func ExtractFromCell ¶
func MetasheetOptions ¶ added in v0.9.12
func MetasheetOptions() *tableaupb.WorksheetOptions
func SetMetasheetName ¶ added in v0.10.6
func SetMetasheetName(name string)
SetMetasheetName change the metasheet name to the specified name.
NOTE: If will not change MetasheetName value if the specified name is empty.
Types ¶
type Book ¶
type Book struct {
// contains filtered or unexported fields
}
func NewBook ¶
func NewBook(bookName, filename string, parser SheetParser) *Book
NewBook creates a new book. Example:
- bookName: Test
- filename: testdata/Test.xlsx
func (*Book) ExportExcel ¶
func (*Book) Metabook ¶ added in v0.10.6
func (b *Book) Metabook() *internalpb.Metabook
Metabook returns the metadata of this book.
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 }
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) GetMetaKeyname ¶ added in v0.11.0
GetMetaKeyname returns this node's @keyname defined in schema sheet.
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 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.
type RowCell ¶
type RowCells ¶
type RowCells struct { SheetName string Row int // row number // contains filtered or unexported fields }
func (*RowCells) CellDebugKV ¶ added in v0.10.6
func (*RowCells) GetCellCountWithPrefix ¶
func (*RowCells) SetColumnLookupTable ¶ added in v0.10.7
func (r *RowCells) SetColumnLookupTable(table ColumnLookupTable)
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) 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
Table represents a 2D array table.
func (*Table) ExportExcel ¶ added in v0.11.0
ExportExcel exports Table to excel sheet.
func (*Table) ExtractBlock ¶ added in v0.12.0
ExtractBlock extracts a block of rows.
NOTE: A block is a series of contiguous none-empty rows. So different blocks are seperated by one or more empty rows.
func (*Table) FindBlockEndRow ¶ added in v0.12.0
FindBlockEndRow finds the end row of the block. If the start row is empty, it will just return the start row. Otherwise, it will return the last none-empty row.
NOTE: A block is a series of contiguous none-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) IsRowEmpty ¶ added in v0.12.0
IsRowEmpty checks whether the whole row is empty.