Documentation ¶
Overview ¶
table provides a struct to handle tabular data.
Index ¶
- Constants
- func SimpleTable(table Table) string
- func StreamSimpleTable(qw422016 *qt422016.Writer, table Table)
- func WriteCSVSimple(cols []string, rows [][]string, filename string) error
- func WriteSimpleTable(qq422016 qtio422016.Writer, table Table)
- func WriteXLSX(path string, tables ...*Table) error
- func WriteXLSXInterface(filename string, sheetdatas ...SheetData) error
- type Columns
- func (cols Columns) CellFloat64(colName string, row []string) (float64, error)
- func (cols Columns) CellInt(colName string, row []string) (int, error)
- func (cols Columns) CellString(colName string, row []string) (string, error)
- func (cols Columns) CellTime(colName, timeFormat string, row []string) (time.Time, error)
- func (cols Columns) CellsString(colNames []string, row []string) ([]string, error)
- func (cols Columns) Equal(c Columns) bool
- func (cols Columns) Index(colName string) int
- func (cols Columns) MustCellString(colName string, row []string) string
- func (cols Columns) MustCellsString(colNames []string, row []string) []string
- func (cols Columns) RowMap(row []string, omitEmpty bool) map[string]string
- type ParseOptions
- type SheetData
- type Table
- func (tbl *Table) ColumnSumFloat64(colIdx uint) (float64, error)
- func (tbl *Table) ColumnValues(colIdx uint, dedupeValues, sortResults bool) ([]string, error)
- func (tbl *Table) ColumnValuesForColumnName(colName string, dedupeValues, sortValues bool) ([]string, error)
- func (tbl *Table) ColumnValuesMinMax(colIdx uint) (string, string, error)
- func (tbl *Table) ColumnsValuesDistinct(wantCols []string, stripSpace bool) (map[string]int, error)
- func (tbl *Table) FilterRecordsColumnValues(wantColNameValues map[string]string) ([][]string, error)
- func (tbl *Table) FormatColumn(colIdx uint, conv func(cellVal string) (string, error)) error
- func (tbl *Table) FormatterFunc() func(val string, colIdx uint) (interface{}, error)
- func (tbl *Table) IsWellFormed() (isWellFormed bool, columnCount uint)
- func (tbl *Table) LoadMergedRows(data [][]string)
- func (tbl *Table) NewTableFilterColDistinctFirst(colIdx int) *Table
- func (tbl *Table) NewTableFilterColumnValues(wantColNameValues map[string]string) (Table, error)
- func (tbl *Table) Pivot(colCount uint, haveColumns bool) (Table, error)
- func (tbl *Table) RowCellCounts() map[int]int
- func (tbl *Table) String(comma rune, useCRLF bool) (string, error)
- func (tbl *Table) ToDocuments() []map[string]interface{}
- func (tbl *Table) ToHTML(escapeHTML bool) string
- func (tbl *Table) ToSliceMSS() []map[string]string
- func (tbl *Table) Unmarshal(funcRow func(row []string) error) error
- func (tbl *Table) UpsertRowColumnValue(rowIdx, colIdx uint, value string)
- func (tbl *Table) WriteCSV(path string) error
- func (tbl *Table) WriteJSON(path string, perm os.FileMode, jsonPrefix, jsonIndent string) error
- func (tbl *Table) WriteXLSX(path, sheetname string) error
- type TableSet
Constants ¶
const ( FormatFloat = "float" FormatInt = "int" FormatString = "string" FormatTime = "time" StyleSimple = "border:1px solid #000;border-collapse:collapse" )
Variables ¶
This section is empty.
Functions ¶
func SimpleTable ¶
func StreamSimpleTable ¶
func WriteCSVSimple ¶
WriteCSVSimple writes a file with cols and rows data.
func WriteSimpleTable ¶
func WriteSimpleTable(qq422016 qtio422016.Writer, table Table)
func WriteXLSXInterface ¶
Types ¶
type Columns ¶ added in v1.5.0
type Columns []string
Columns represents a slice of string with tabular functions.
func (Columns) CellFloat64 ¶ added in v1.14.4
CellFloat64 returns a single row value.
func (Columns) CellString ¶ added in v1.14.4
CellString returns a single row value.
func (Columns) CellTime ¶ added in v1.14.4
CellTime returns a single row value. If no `timeFormat` is provided `time.RFC3339` is used.
func (Columns) CellsString ¶ added in v1.14.4
CellsString returns a slice of values.
func (Columns) Equal ¶ added in v1.13.0
Equal returns true if the number of elements or the element values of the Columns do not match.
func (Columns) Index ¶ added in v1.5.0
Index returns the column index of the requested column name. A value of `-1` is returned if the coliumn name is not found.
func (Columns) MustCellString ¶ added in v1.14.4
MustCellString returns a single row value or empty string if the column name doesn't exist.
func (Columns) MustCellsString ¶ added in v1.14.4
MustCellsString returns a slice of values.
type ParseOptions ¶ added in v1.12.0
type ParseOptions struct { UseComma bool Comma rune NoHeader bool // HasHeader is default (false) FieldsPerRecord int FilterColNames []string FilterColIndices []uint TrimSpace bool }
ParseOptions provides a set of configuraation parameters for parsing a CSV file. If an empty or nil `ParseOptions` is provided to `ReadFile`, default options for reading files will be used.
func (*ParseOptions) CommaValue ¶ added in v1.12.0
func (opts *ParseOptions) CommaValue() rune
func (*ParseOptions) HasFilter ¶ added in v1.12.0
func (opts *ParseOptions) HasFilter() bool
type Table ¶
type Table struct { Name string Columns Columns Rows [][]string FormatMap map[int]string FormatFunc func(val string, colIdx uint) (interface{}, error) FormatAutoLink bool ID string Class string Style string }
Table is useful for working on CSV data. It stores records as `[]string` with typed formatting information per-column to facilitate transformations.
func NewTable ¶
NewTable returns a new empty `Table` struct with slices and maps set to empty (non-nil) values.
func ParseReadSeeker ¶ added in v1.16.1
func ParseReadSeeker(opts *ParseOptions, rs io.ReadSeeker) (Table, error)
ParseReadSeeker parses an `io.ReadSeeker` and returns a `Table` struct.
func ReadFile ¶
func ReadFile(opts *ParseOptions, filenames ...string) (Table, error)
ReadFile reads one or more delimited files and returns a merged `Table` struct. An error is returned if the columns count differs between files.
func (*Table) ColumnValues ¶
func (*Table) ColumnValuesForColumnName ¶ added in v1.5.0
func (*Table) ColumnValuesMinMax ¶
func (*Table) ColumnsValuesDistinct ¶
func (*Table) FilterRecordsColumnValues ¶
func (tbl *Table) FilterRecordsColumnValues(wantColNameValues map[string]string) ([][]string, error)
FilterRecordsColumnValues returns a set of records filtered by column names and column values.
func (*Table) FormatColumn ¶ added in v1.15.0
FormatColumn takes a function to format all cell values.
func (*Table) FormatterFunc ¶
func (*Table) IsWellFormed ¶
func (*Table) LoadMergedRows ¶
LoadMergedRows is used to load data including both column names and rows from `[][]string` sources like `csv.ReadAll()`.
func (*Table) NewTableFilterColDistinctFirst ¶
func (*Table) NewTableFilterColumnValues ¶
NewTableFilterColumnValues returns a Table filtered by column names and column values.
func (*Table) Pivot ¶ added in v1.15.0
Pivot takes a "straight table" where the columnn names and values are in a single column and lays it out as a standard tabular data.
func (*Table) RowCellCounts ¶ added in v1.15.0
RowCellCounts returns a `map[int]int` where the key is the cell count and the value is the number of rows.
func (*Table) ToDocuments ¶ added in v1.6.0
func (*Table) ToSliceMSS ¶
func (*Table) Unmarshal ¶
Unmarshal is a convenience function to provide a simple interface to unmarshal table contents into any desired output.
func (*Table) UpsertRowColumnValue ¶
type TableSet ¶
type TableSet struct { Name string Columns []string FormatMap map[int]string FormatFunc func(val string, colIdx uint) (interface{}, error) TableMap map[string]*Table }