excel

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package excel provides Excel import and export for the pulse I/O pipeline.

Package excel provides Excel import and export for the pulse I/O pipeline.

Index

Constants

View Source
const OverlaySheetPrefix = "__overlay_"

OverlaySheetPrefix is the reserved sheet-name prefix every embedded overlay sheet carries. Authors filter overlay sheets with strings.HasPrefix(name, OverlaySheetPrefix). Author-supplied sheets MUST NOT start with this prefix; the prefix is reserved for the engine.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*config)

Option configures Excel reader or writer behavior.

func WithSheet

func WithSheet(name string) Option

WithSheet selects a named sheet to read from or write to.

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader reads tabular data from an Excel (.xlsx) file.

func NewReader

func NewReader(fs afero.Fs, path string, opts ...Option) *Reader

NewReader creates an Excel reader from a filesystem path.

func NewReaderFromBytes

func NewReaderFromBytes(data []byte, opts ...Option) *Reader

NewReaderFromBytes creates an Excel reader from raw bytes.

func (*Reader) Close

func (r *Reader) Close() error

Close releases resources.

func (*Reader) ReadHeader

func (r *Reader) ReadHeader() ([]string, error)

ReadHeader returns the column names from the first row.

func (*Reader) ReadOverlays added in v0.19.0

func (r *Reader) ReadOverlays() ([]*types.OverlayLayer, error)

ReadOverlays walks every "__overlay_*" sheet on the workbook and reconstructs the embedded []*types.OverlayLayer slice. Returns nil (not error) when the workbook carries no overlay sheets — the contract is "no overlays present" rather than "field missing is an error" (mirrors the Arrow / Parquet ReadOverlays surface).

Round-trip is best-effort per research/export-embedding-shape.md § 5.3 — Excel coerces some numeric edge cases (NaN, Inf, very-small / very-large floats) to text strings on write, so the reader treats each cell as a float64 best-effort and tolerates ±1 ULP on numeric values. The shape (kind / scope / ref / payload shape / per-entry keys / per-cell present flag / summary slots) is preserved exactly.

Sheet emission order is the source of truth for layer slot order (matches Response.Overlays slot order at export time). The reader returns layers in the order it discovers overlay sheets on the workbook.

func (*Reader) ReadRows

func (r *Reader) ReadRows(ctx context.Context, fn func(row []string) error) error

ReadRows streams rows to fn. ReadHeader must be called first.

func (*Reader) Reset

func (r *Reader) Reset() error

Reset rewinds the reader to the beginning.

func (*Reader) SheetNames added in v0.19.0

func (r *Reader) SheetNames() ([]string, error)

SheetNames returns the list of sheet names on the workbook. Overlay sheets ride alongside the host data sheet with the OverlaySheetPrefix reserved namespace ("__overlay_*"); callers introspecting the overlay layout filter by HasPrefix on the prefix constant.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer writes tabular data to an Excel (.xlsx) file.

func NewWriter

func NewWriter(fs afero.Fs, path string, opts ...Option) *Writer

NewWriter creates an Excel writer targeting a filesystem path.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes and writes the workbook to the target path. When SetOverlays handed the writer a non-empty layer slice the writer appends one "__overlay_<layer_name>" sheet per layer after the host sheet's stream writer is flushed and before WriteToBuffer; see writeOverlaySheets in overlay.go for the layout rules.

func (*Writer) SetOverlays added in v0.19.0

func (w *Writer) SetOverlays(layers []*types.OverlayLayer)

SetOverlays records the Response.Overlays layers the export pipeline wants the writer to embed in the workbook. Each layer lands on a dedicated sheet named "__overlay_<layer_name>" alongside the host data sheet per research/export-embedding-shape.md § 5 (one sheet per layer; the double-underscore prefix reserves the namespace). nil or empty layers leave the workbook byte-identical to a pre-overlay export (no overlay sheets land). Implements pio.OverlayAwareWriter.

Sheet emission happens at Close() time so the host sheet's stream writer can finish writing before the overlay sheets are appended. Must be called BEFORE Close.

func (*Writer) SetPulseSchema added in v0.2.0

func (w *Writer) SetPulseSchema(s *encoding.Schema)

SetPulseSchema records the source .pulse schema. Implements pio.SchemaAwareWriter so ExportJob can hand the writer typed values for decimal128 columns.

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(columns []string) error

WriteHeader writes column names as the first row.

func (*Writer) WriteRow

func (w *Writer) WriteRow(values []any) error

WriteRow writes a single data row. With a Pulse schema set the writer renders decimal128 cells as Excel numbers with a scale-driven "0.000…" format. Without a schema, values pass through excelize's default cell-value handling.

Jump to

Keyboard shortcuts

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