Help us shape the future of Go! Take the 2026 Go Developer Survey

sheet

package
v0.57.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package sheet implements spreadsheet type inference: it profiles XLSX/CSV workbooks into per-sheet SheetProfile structures (column types, affinities, min/max, distinct values and sample rows) and the SQLite DDL that matches them. It is a leaf package — it must not import other project packages — so both internal/indexer (document indexing) and internal/tool (query_sheet) can consume it without cycles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProfileText

func ProfileText(p SheetProfile) string

ProfileText renders the profile text a sheet page is indexed from: sheet name, dimensions, per-column type/affinity, min/max, distinct values and the sample rows.

func StreamRows

func StreamRows(path, sheet string, feed func([]string) error) error

StreamRows feeds the data rows of one sheet (header row excluded) to feed in reading order, one []string per row. Each value arrives as the SAME normalized display string the profiler folded into its accumulators — the row is run through classifyCell with the workbook's own signals — so a table loaded from this stream agrees cell for cell with the profile's Sample, Min/Max and Distinct values: Excel serial dates come through as ISO-8601 text, declared booleans as TRUE/FALSE, everything else verbatim. Delimited text has exactly one sheet ("Sheet1") and its sheet argument is ignored. An error from feed aborts the stream and is returned as-is.

Types

type SheetColumn

type SheetColumn struct {
	Name     string
	Type     string
	Affinity string
	Min      string
	Max      string
	Distinct []string
}

SheetColumn is the per-column verdict shared with the query_sheet tool: Type is the inferred kind ("integer" | "number" | "date" | "boolean" | "text" | "empty"), Affinity the SQLite affinity the emitted SQL carries (integer→INTEGER; number→REAL; date/text/boolean/empty→TEXT), Min/Max the normalized extrema ("" when unset, dates ISO-8601) and Distinct the top ≤8 values when the column has ≤12 distinct non-empty values, else nil.

type SheetProfile

type SheetProfile struct {
	Name    string
	Rows    int
	Cols    int
	Headers []string
	Columns []SheetColumn
	SQL     string
	Total   int
	Sample  [][]string
}

SheetProfile is the per-sheet contract shared with the query_sheet tool. SQL is complete, executable SQLite DDL on a modernc.org/sqlite connection. Sample holds up to sampleRowCount leading data rows as normalized display values (extra field beyond the contract, for the indexed page text).

func ProfileCSV

func ProfileCSV(path string) ([]SheetProfile, error)

ProfileCSV profiles a delimited-text file: delimiter , ; \t sniffed, UTF-8/UTF-16 BOM handled, blank leading rows skipped and the first row carrying a value taken as the header (headerGate — the rule streamCSV streams past), and exactly one profile named "Sheet1".

func ProfileXLSX

func ProfileXLSX(path string) ([]SheetProfile, error)

ProfileXLSX profiles every sheet of an xlsx/xlsm workbook — one profile per sheet. Sheets stream through the row iterator (never materialized); the number-format date signal is looked up per style id and cached.

Jump to

Keyboard shortcuts

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