sheet

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package sheet is the CLI's canonical spreadsheet model plus parsers and emitters for CSV, TSV, JSON, JSONL and XLSX. It mirrors the Demografix browser tool's semantics so enriched output matches the web download.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CellToString

func CellToString(c Cell) string

CellToString stringifies a cell exactly like the Elixir cell_to_string/1.

func DetectAndDecode

func DetectAndDecode(b []byte) (string, Encoding, BOM, error)

DetectAndDecode decodes input bytes to a UTF-8 string, detecting a BOM and falling back to Windows-1252 for non-UTF-8 input without a BOM.

func FormatFloatShort

func FormatFloatShort(f float64) string

FormatFloatShort renders a float exactly like Erlang :short / Jason: the shortest round-trip digits, formatted positionally or in scientific notation (whichever is shorter; ties prefer positional), always keeping a decimal point. The mantissa carries a ".0" when whole, and the exponent is printed without a leading zero or '+' (e.g. "1.0e3", "1.23e-4", "0.0001").

func WriteFile

func WriteFile(path string, s *Spreadsheet) error

WriteFile writes the spreadsheet to a file path.

func WriteTo

func WriteTo(w io.Writer, s *Spreadsheet) error

WriteTo emits the spreadsheet in its Format.

Types

type BOM

type BOM int

BOM records the detected byte-order mark.

const (
	BOMNone BOM = iota
	BOMUTF8
	BOMUTF16LE
	BOMUTF16BE
)

type Cell

type Cell = any

Cell is one canonical cell value: nil | string | int64 | float64 | bool | DateCell | DateTimeCell | []Cell | map[string]Cell.

type DateCell

type DateCell time.Time

DateCell is a date-only value; DateTimeCell carries a time component.

type DateTimeCell

type DateTimeCell time.Time

DateCell is a date-only value; DateTimeCell carries a time component.

type Encoding

type Encoding int

Encoding records the detected input encoding (output is always UTF-8).

const (
	EncUTF8 Encoding = iota
	EncUTF16LE
	EncUTF16BE
	EncWindows1252
)

type Format

type Format int

Format is a spreadsheet file format.

const (
	CSV Format = iota
	TSV
	JSON
	JSONL
	XLSX
)

func ResolveOutput

func ResolveOutput(inputFormat Format, outputPath string) (Format, error)

ResolveOutput picks the output format from the -o file extension, or mirrors the input format when no output path is given. .xls/.xlsm always emit .xlsx.

type JSONTop

type JSONTop int

JSONTop is the top-level shape of a JSON document.

const (
	TopArray JSONTop = iota
	TopDataObject
)

type Meta

type Meta struct {
	Delimiter rune    // CSV/TSV
	TopLevel  JSONTop // JSON
	SheetName string  // XLSX
}

Meta carries format-specific parsing details needed to re-emit faithfully.

func DefaultMeta

func DefaultMeta(f Format) Meta

DefaultMeta returns sensible Meta when converting to a format.

type RawNumber

type RawNumber string

RawNumber preserves a numeric literal that cannot be represented as a Go int64/float64 without loss (e.g. a 20-digit id). It is emitted verbatim.

type Spreadsheet

type Spreadsheet struct {
	Format   Format
	Headers  []string
	Rows     [][]Cell
	Encoding Encoding
	BOM      BOM
	Meta     Meta
}

Spreadsheet is the materialized representation of a parsed file.

func Parse

func Parse(path string) (*Spreadsheet, error)

Parse reads and parses a spreadsheet file, dispatching by extension.

type UnsupportedFormatError

type UnsupportedFormatError struct {
	Ext    string
	Output bool
}

UnsupportedFormatError is returned for an unrecognized input or output file extension. The CLI maps it to a usage exit code.

func (*UnsupportedFormatError) Error

func (e *UnsupportedFormatError) Error() string

Jump to

Keyboard shortcuts

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