table

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ExcelMaxColCount = 16384
	ExcelMaxRowCount = 1048576
	Alphabet         = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
	ZZ               = uint32(702)
	ZZIndex          = uint32(701)
)

Variables

View Source
var DebugReadCSV = false // should not need to use this.

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 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 WriteCSV

func WriteCSV(path string, t *TableData) error

WriteCSV writes the table as a CSV.

func WriteCSVSimple

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

WriteCSVSimple writes a file with cols and records data.

func WriteXLSX

func WriteXLSX(path string, tbls ...*TableData) error

WriteXLSX writes a table as an Excel XLSX file.

func WriteXLSXFormatted added in v1.0.0

func WriteXLSXFormatted(path string, tbls ...*TableFormatter) error

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

Types

type DocumentsSet

type DocumentsSet struct {
	Meta      DocumentsSetMeta    `json:"meta"`
	Documents []map[string]string `json:"records"`
}

func NewDocumentsSet

func NewDocumentsSet() DocumentsSet

func (*DocumentsSet) CreateHistogram

func (ds *DocumentsSet) CreateHistogram(key string)

func (*DocumentsSet) Inflate

func (ds *DocumentsSet) Inflate()

type DocumentsSetMeta

type DocumentsSetMeta struct {
	Count      int                            `json:"count"`
	Histograms map[string]histogram.Histogram `json:"histograms"`
}

func NewDocumentsSetMeta

func NewDocumentsSetMeta() DocumentsSetMeta

type TableData added in v1.0.0

type TableData struct {
	Name    string
	Columns []string
	Records [][]string
}

TableData is useful for working on CSV data

func NewTableData added in v1.0.0

func NewTableData() TableData

func (*TableData) ColumnIndex added in v1.0.0

func (t *TableData) ColumnIndex(wantCol string) int

func (*TableData) ColumnValuesDistinct added in v1.0.0

func (t *TableData) ColumnValuesDistinct(wantCol string) (map[string]int, error)

func (*TableData) ColumnValuesMinMax added in v1.0.0

func (t *TableData) ColumnValuesMinMax(wantCol string) (string, string, error)

func (*TableData) ColumnsValuesDistinct added in v1.0.0

func (t *TableData) ColumnsValuesDistinct(wantCols []string, stripSpace bool) (map[string]int, error)

func (*TableData) FilterRecords added in v1.0.0

func (t *TableData) FilterRecords(wantColValues map[string]string) ([][]string, error)

func (*TableData) LoadMergedRows added in v1.0.0

func (t *TableData) LoadMergedRows(data [][]string)
func NewTableDataCSV(path string, comma rune, stripBom bool) (TableData, error) {
	tbl := NewTableData()
	csv, file, err := csvutil.NewReader(path, comma, stripBom)
	if err != nil {
		return tbl, err
	}
	defer file.Close()
	mergedRows, err := csv.ReadAll()
	if err != nil {
		return tbl, err
	}
	tbl.LoadMergedRows(mergedRows)
	return tbl, nil
}

LoadMergedRows is used to load data from `[][]string` sources like csv.ReadAll()

func (*TableData) NewTableFiltered added in v1.0.0

func (t *TableData) NewTableFiltered(wantColValues map[string]string) (TableData, error)

func (*TableData) RecordToMSS added in v1.0.0

func (t *TableData) RecordToMSS(record []string) map[string]string

func (*TableData) RecordValue added in v1.0.0

func (t *TableData) RecordValue(wantCol string, record []string) (string, error)

func (*TableData) RecordValueOrEmpty added in v1.0.0

func (t *TableData) RecordValueOrEmpty(wantCol string, record []string) string

func (*TableData) ToSliceMSS added in v1.0.0

func (t *TableData) ToSliceMSS() []map[string]string

func (*TableData) WriteCSV added in v1.0.0

func (t *TableData) WriteCSV(path string) error

func (*TableData) WriteJSON added in v1.0.0

func (t *TableData) WriteJSON(path string, perm os.FileMode, jsonPrefix, jsonIndent string) error

func (*TableData) WriteXLSX added in v1.0.0

func (t *TableData) WriteXLSX(path, sheetname string) error

type TableFormatter added in v1.0.0

type TableFormatter struct {
	Table     *TableData
	Formatter func(val string, colIdx uint) (interface{}, error)
}

type TableSet

type TableSet struct {
	Columns      []string
	RowFormatter func(val string, col uint) (interface{}, error)
	TableMap     map[string]*TableFormatter
}

func (*TableSet) AddRecord

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

func (*TableSet) TableNames

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

func (*TableSet) TablesFormattedSorted added in v1.0.0

func (ts *TableSet) TablesFormattedSorted() []*TableFormatter

Jump to

Keyboard shortcuts

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