excel

package
v1.1.10 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package excel builds spreadsheet workbooks from a declarative description of columns and rows, with no knowledge of any domain type.

Index

Constants

View Source
const ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"

identifies the workbooks this package produces

Variables

View Source
var ErrNoSheets = errors.New("excel: a workbook needs at least one sheet")

reports a spec that would produce a file Excel refuses to open

Functions

func Build

func Build(spec Spec) ([]byte, error)

renders a spec to xlsx bytes

func Date

func Date(v *time.Time) string

renders an optional date the way the rest of a sheet does; an unset date is blank

func Filename

func Filename(slug string, at time.Time) string

names an export's file from its resource slug, e.g. "unit_groups_export_07-30-2026.xlsx". One separator throughout, so the name survives a URL path without escaping.

func FilenameWithExt

func FilenameWithExt(slug string, at time.Time, ext string) string

FilenameWithExt names an export's file in a given format. The extension is part of the object key, and the browser takes the download's name from that key — so an export that is not a spreadsheet must say so here or it is saved under an extension that will not open.

func JoinNames

func JoinNames(names []string) string

flattens a child collection into a single cell

func Str

func Str(v *string) string

dereferences an optional string into a cell value, since a blank cell and an absent value are the same thing to Excel

Types

type ColumnSpec

type ColumnSpec struct {
	Header string
	Key    string
	Width  float64
	// NumFmt is an Excel custom number format applied to the column's data cells.
	NumFmt string
	// Note is a hover comment on the header cell.
	Note string
}

describes one column. Rows address it by Key; nothing outside this package computes a column letter, which is what stops the two diverging.

type Row

type Row map[string]any

carries one row's cells keyed by ColumnSpec.Key; a missing key is blank

func Group

func Group(parent Row, children []Row) []Row

expands a parent across its children, one row per child, with the parent's cells on the first row only. A childless parent still emits a row, so none disappears.

type Sheet

type Sheet struct {
	Name    string
	Columns []ColumnSpec
	Rows    []Row
}

describes one worksheet

type Spec

type Spec struct {
	Sheets []Sheet
}

describes a whole workbook

Jump to

Keyboard shortcuts

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