table

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2021 License: MIT Imports: 22 Imported by: 1

Documentation

Overview

table provides a struct to handle tabular data.

Index

Constants

View Source
const (
	ExcelMaxColCount = 16384
	ExcelMaxRowCount = 1048576
	Alphabet         = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	ZZ               = uint32(702)
	ZZIndex          = uint32(701)
)
View Source
const (
	FormatFloat  = "float"
	FormatInt    = "int"
	FormatString = "string"
	FormatTime   = "time"
	StyleSimple  = "border:1px solid #000;border-collapse:collapse"
)

Variables

This section is empty.

Functions

func ColIndexToLetters

func ColIndexToLetters(colIndex uint32) string

func ColNumberToLetters

func ColNumberToLetters(colNumber uint32) string

func CoordinateNumbersToSheetLocation

func CoordinateNumbersToSheetLocation(colNum, rowNum uint32) string

CoordinateNumbersToSheetLocation converts x, y integer coordinates to a spreadsheet location such as "AA1" for col 27, row 1.

func CoordinatesToSheetLocation

func CoordinatesToSheetLocation(colIdx, rowIdx uint32) string

CoordinatesToSheetLocation converts x, y integer coordinates to a spreadsheet location such as "AA1" for col 27, row 1.

func FormatDateAndFloats added in v1.3.0

func FormatDateAndFloats(val string, colIdx uint) (interface{}, error)

func FormatMonthAndFloats added in v1.3.0

func FormatMonthAndFloats(val string, colIdx uint) (interface{}, error)

func FormatStringAndFloats

func FormatStringAndFloats(val string, colIdx uint) (interface{}, error)

func FormatStringAndInts

func FormatStringAndInts(val string, colIdx uint) (interface{}, error)

func FormatStrings

func FormatStrings(val string, col uint) (interface{}, error)

func FormatTimeAndFloats

func FormatTimeAndFloats(val string, colIdx uint) (interface{}, error)

func FormatTimeAndInts

func FormatTimeAndInts(val string, colIdx uint) (interface{}, error)

func ReadCSVFileSingleColumnValuesString

func ReadCSVFileSingleColumnValuesString(filename string, sep rune, hasHeader bool, col uint, condenseUniqueSort bool) ([]string, error)

func ReadCSVFilesSingleColumnValuesString

func ReadCSVFilesSingleColumnValuesString(files []string, sep rune, hasHeader bool, col uint, condenseUniqueSort bool) ([]string, error)

func SimpleTable

func SimpleTable(table Table) string

func StreamSimpleTable

func StreamSimpleTable(qw422016 *qt422016.Writer, table Table)

func WriteCSVSimple

func WriteCSVSimple(cols []string, rows [][]string, filename string) error

WriteCSVSimple writes a file with cols and rows data.

func WriteSimpleTable

func WriteSimpleTable(qq422016 qtio422016.Writer, table Table)

func WriteXLSX

func WriteXLSX(path string, tables ...*Table) error

WriteXLSX writes a table as an Excel XLSX file with row formatter option.

func WriteXLSXInterface

func WriteXLSXInterface(filename string, sheetdatas ...SheetData) error

Types

type Column added in v0.0.4

type Column struct {
	Display string
	Slug    string
	Width   float64
}

type ColumnSet added in v0.0.4

type ColumnSet struct {
	Columns []Column
}

func (*ColumnSet) DisplayTexts added in v0.0.4

func (set *ColumnSet) DisplayTexts() []string

type Columns added in v1.5.0

type Columns []string

Columns represents a slice of string with tabular functions.

func (Columns) Index added in v1.5.0

func (cols Columns) Index(colName string) int

func (Columns) MustRowVal added in v1.5.0

func (cols Columns) MustRowVal(colName string, row []string) string

MustRowVal returns a single row value.

func (Columns) MustRowVals added in v1.5.0

func (cols Columns) MustRowVals(colNames []string, row []string) []string

MustRowVals returns a slice of values.

func (Columns) RowMap added in v1.5.0

func (cols Columns) RowMap(row []string, omitEmpty bool) map[string]string

RowMap converts a CSV row to a `map[string]string`.

func (Columns) RowVal added in v1.5.0

func (cols Columns) RowVal(colName string, row []string) (string, error)

RowVal returns a single row value.

func (Columns) RowValFloat64 added in v1.5.0

func (cols Columns) RowValFloat64(colName string, row []string) (float64, error)

RowValFloat64 returns a single row value.

func (Columns) RowValInt added in v1.5.0

func (cols Columns) RowValInt(colName string, row []string) (int, error)

RowValInt returns a single row value.

func (Columns) RowValTime added in v1.5.0

func (cols Columns) RowValTime(colName, timeFormat string, row []string) (time.Time, error)

RowValTime returns a single row value. If no `timeFormat` is provided `time.RFC3339` is used.

func (Columns) RowVals added in v1.5.0

func (cols Columns) RowVals(colNames []string, row []string) ([]string, error)

RowVals returns a slice of values.

type SheetData

type SheetData struct {
	SheetName string
	Rows      [][]interface{}
}

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 FormatStraightToTabular

func FormatStraightToTabular(tbl Table, colCount uint) (Table, error)

FormatStraightToTabular takes a "straight table" wheere the columnn names and values are in a single column and lays it out as a standard tabular data.

func NewTable

func NewTable(name string) Table

NewTable returns a new empty `Table` struct with slices and maps set to empty (non-nil) values.

func ParseBytes

func ParseBytes(data []byte, delimiter rune, hasHeaderRow bool) (Table, error)

func ParseReader

func ParseReader(reader io.Reader, delimiter rune, hasHeaderRow bool) (Table, error)

func ReadFile

func ReadFile(filename string, comma rune, hasHeader bool) (Table, error)

ReadFile reads in a delimited file and returns a `Table` struct.

func ReadFiles added in v1.5.0

func ReadFiles(filenames []string, comma rune, hasHeader bool) (Table, error)

ReadFiles reads in a list of delimited files and returns a merged `Table` struct. An error is returned if the columns count differs between files.

func (*Table) ColumnSumFloat64

func (tbl *Table) ColumnSumFloat64(colIdx uint) (float64, error)

func (*Table) ColumnValues

func (tbl *Table) ColumnValues(colIdx uint, dedupeValues, sortResults bool) ([]string, error)

func (*Table) ColumnValuesDistinct

func (tbl *Table) ColumnValuesDistinct(colIdx uint) (map[string]int, error)

func (*Table) ColumnValuesForColumnName added in v1.5.0

func (tbl *Table) ColumnValuesForColumnName(colName string, dedupeValues, sortValues bool) ([]string, error)

func (*Table) ColumnValuesMinMax

func (tbl *Table) ColumnValuesMinMax(colIdx uint) (string, string, error)

func (*Table) ColumnsValuesDistinct

func (tbl *Table) ColumnsValuesDistinct(wantCols []string, stripSpace bool) (map[string]int, error)

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) FormatterFunc

func (tbl *Table) FormatterFunc() func(val string, colIdx uint) (interface{}, error)

func (*Table) IsWellFormed

func (tbl *Table) IsWellFormed() (isWellFormed bool, columnCount uint)

func (*Table) LoadMergedRows

func (tbl *Table) LoadMergedRows(data [][]string)

LoadMergedRows is used to load data including both column names and rows from `[][]string` sources like `csv.ReadAll()`.

func (*Table) NewTableFilterColDistinctFirst

func (tbl *Table) NewTableFilterColDistinctFirst(colIdx int) *Table

func (*Table) NewTableFilterColumnValues

func (tbl *Table) NewTableFilterColumnValues(wantColNameValues map[string]string) (Table, error)

NewTableFilterColumnValues returns a Table filtered by column names and column values.

func (*Table) ToDocuments added in v1.6.0

func (tbl *Table) ToDocuments() []map[string]interface{}

func (*Table) ToHTML added in v1.6.0

func (tbl *Table) ToHTML(escapeHTML bool) string

ToHTML converts `*TableData` to HTML.

func (*Table) ToSliceMSS

func (tbl *Table) ToSliceMSS() []map[string]string

func (*Table) Unmarshal

func (tbl *Table) Unmarshal(funcRow func(row []string) error) error

Unmarshal is a convenience function to provide a simple interface to unmarshal table contents into any desired output.

func (*Table) UpsertRowColumnValue

func (tbl *Table) UpsertRowColumnValue(rowIdx, colIdx uint, value string)

func (*Table) WriteCSV

func (tbl *Table) WriteCSV(path string) error

func (*Table) WriteJSON

func (tbl *Table) WriteJSON(path string, perm os.FileMode, jsonPrefix, jsonIndent string) error

func (*Table) WriteXLSX

func (tbl *Table) WriteXLSX(path, sheetname string) error

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
}

func NewTableSet added in v1.10.0

func NewTableSet(name string) TableSet

func (*TableSet) AddRow added in v1.6.0

func (ts *TableSet) AddRow(tableName string, row []string)

func (*TableSet) TableNames

func (ts *TableSet) TableNames() []string

func (*TableSet) TablesSorted

func (ts *TableSet) TablesSorted() []*Table

type TabulatorColumn added in v0.0.4

type TabulatorColumn struct {
	Title        string  `json:"title,omitempty"`
	Field        string  `json:"field,omitempty"`
	Width        float64 `json:"width,omitempty"`
	HeaderFilter string  `json:"headerFilter,omitempty"`
}

type TabulatorColumnSet added in v0.0.4

type TabulatorColumnSet struct {
	Columns []TabulatorColumn
}

func BuildColumnsTabulator added in v0.0.4

func BuildColumnsTabulator(columns []Column) TabulatorColumnSet

func (*TabulatorColumnSet) ColumnsJSON added in v0.0.4

func (tColSet *TabulatorColumnSet) ColumnsJSON() ([]byte, error)

func (*TabulatorColumnSet) MustColumnsJSON added in v0.0.4

func (tColSet *TabulatorColumnSet) MustColumnsJSON() []byte

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL