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

spreadsheet

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Overview

Package spreadsheet is the spreadsheet deliverable: budget, bookkeeping and tracker templates described in workbook.json, built as .xlsx files per edition, computed and checked by lfm's own formula engine on every compile and, when installed, by LibreOffice on a release, and delivered with a Google Sheets copy link the owner creates once.

Index

Constants

View Source
const (
	Empty   = "empty"
	Example = "example"
)

Datasets the files are built from: the blank template and, when the workbook has one, the filled example.

View Source
const (
	Dir          = "deliverables/spreadsheet"
	ConceptFile  = Dir + "/concept.md"
	WorkbookName = "workbook.json"
	WorkbookFile = Dir + "/" + WorkbookName
	ListingFile  = Dir + "/listing.md"
)

The layout under deliverables/spreadsheet.

View Source
const (
	RuleConfig   = "spreadsheet.config"
	RuleConcept  = "spreadsheet.concept"
	RuleWorkbook = "spreadsheet.workbook"
	RuleFormulas = "spreadsheet.formulas"
	RuleCompat   = "spreadsheet.compat"
	RuleSheets   = "spreadsheet.sheets"
	RuleDelivery = "spreadsheet.delivery"
	RuleListing  = "spreadsheet.listing"
	RuleChannels = "spreadsheet.channels"
)

Rule IDs.

Variables

View Source
var Sections = []concept.SectionSpec{
	{Name: "Buyer"}, {Name: "Promise"}, {Name: "Tabs"}, {Name: "Look"}, {Name: "Changelog", Optional: true},
}

Sections of the spreadsheet concept, in order.

View Source
var TabColumns = []string{"Tab", "Job"}

TabColumns are the columns of the Tabs table.

Functions

func CopyLink(raw string) string

CopyLink turns a Google Sheets address into the link that makes the buyer a copy, or "".

func Distribution

func Distribution(r Report, files []deliver.File, data map[string][]byte, images []Image, pending bool, day string) (map[string][]byte, []string, []diagnostic.Diagnostic)

Distribution assembles the shop packages from the built files: per edition the blank and example .xlsx and the start PDF, a ZIP per edition when Etsy's five files would not hold them, images, guides and a README.

func DownloadPage

func DownloadPage(r Report, files []deliver.File) []byte

DownloadPage renders the unlisted download page: the Google Sheets copy links first, then the files.

func Office

func Office() (string, error)

Office finds LibreOffice; see office.Find.

func Present

func Present(p project.Project) bool

Present reports whether the project has deliverables/spreadsheet.

func Recalculate

func Recalculate(ctx context.Context, soffice string, files map[string][]byte) (map[string]map[string][][]string, error)

Recalculate opens every file in LibreOffice, recalculates it and returns each sheet's cells as LibreOffice computes them: file name -> sheet name -> rows of raw values. One soffice run serves all files.

func Rules

func Rules() []diagnostic.RuleInfo

Rules describes every spreadsheet rule for the catalog.

func Stamp

func Stamp(tail []byte) string

Stamp is the input key a built .xlsx carries in its zip comment.

Types

type Built

type Built struct {
	Name    string
	Edition Edition
	Dataset string
	Data    []byte
}

Built is one file lfm built for an edition.

type Cell

type Cell struct {
	At        string      `json:"at"`   // report: A1 position; form cells stack from row 2
	Name      string      `json:"name"` // a name formulas use: [income]
	Label     Text        `json:"label"`
	Text      Text        `json:"text"`
	Value     any         `json:"value"` // an input's default
	Formula   string      `json:"formula"`
	Type      string      `json:"type"`  // text, number, money, percent, date, enum, check
	Style     string      `json:"style"` // title, heading, label, input, output, note, total
	Values    TextList    `json:"values"`
	From      string      `json:"from"`
	Highlight []Highlight `json:"highlight"`
	Note      Text        `json:"note"`
	Merge     int         `json:"merge"` // columns the cell spans to the right
}

Cell is one cell of a form or report.

type Chart

type Chart struct {
	Type   string `json:"type"` // pie, doughnut, column, bar, line
	Title  Text   `json:"title"`
	Labels string `json:"labels"` // [sheet.column] or a range placeholder
	Values string `json:"values"`
	At     string `json:"at"`
	Width  int    `json:"width"` // pixels
	Height int    `json:"height"`
}

Chart is a native chart on a report.

type Column

type Column struct {
	Key       string      `json:"key"`
	Title     Text        `json:"title"`
	Type      string      `json:"type"` // text, number, money, percent, date, enum, check
	Values    TextList    `json:"values"`
	From      string      `json:"from"`    // enum: the column its choices come from, as sheet.column
	Formula   string      `json:"formula"` // computed per row; [.other] is this row's cell of another column
	Width     float64     `json:"width"`
	Highlight []Highlight `json:"highlight"`
	Note      Text        `json:"note"` // shown as the header's comment
}

Column is one column of a table.

type Config

type Config struct {
	Path, Offer, Language, Sell, Version string
	Sheets                               map[string]string // edition key (or key-example) -> Google Sheets master
	Seller                               string
}

Config is deliverables.spreadsheet in lfm.json.

type Dataset

type Dataset struct {
	Tables map[string][]Row `json:"tables"`
	Cells  map[string]any   `json:"cells"`
}

Dataset fills inputs: tables by sheet key get rows, named cells values.

type Edition

type Edition struct {
	Key      string `json:"key"`      // e.g. en, de
	Language string `json:"language"` // the language its texts are picked in
	Currency string `json:"currency"` // ISO code: USD, EUR, GBP, CHF
}

Edition is one language and currency the workbook is built in.

type Highlight

type Highlight struct {
	If    string `json:"if"`
	Style string `json:"style"` // good, bad, warn, muted
}

Highlight colors a cell when its condition holds: "<0" or a formula.

type Image

type Image = deliver.Image

Image is one listing image.

type ImagePlan

type ImagePlan struct {
	Name string
	Doc  []byte
}

ImagePlan is one listing image to render: 3000×2250 at twice the density.

type Palette

type Palette struct {
	Accent, Ink, Input, Heading, HeadingInk, Muted, Line string
}

Palette is the look of a workbook: its accent and the tints derived from it.

type Plan

type Plan struct {
	Name, Buyer, Promise string
	Tabs                 []Tab
	Accent               string
	Lines                map[string]int
}

Plan is the parsed concept.

type Pos

type Pos struct{ Col, Row int }

Pos is a cell position; Col and Row count from 1.

type Report

type Report struct {
	Config      Config
	Plan        Plan
	Workbook    Workbook
	Editions    []*edition
	Books       map[string]map[string]*book // edition key -> dataset -> computed book
	Summary     Summary
	Diagnostics []diagnostic.Diagnostic
	Listing     deliver.ShopListing
	Buildable   bool
}

Report is the checked spreadsheet.

func Check

func Check(p project.Project, cfg Config, configured bool, offers map[string]*deliver.Price, site string) Report

Check reads deliverables/spreadsheet: configured tells whether lfm.json has deliverables.spreadsheet; site is the page URL the download path hangs off.

func (Report) Build

func (r Report) Build(previous func(key string) []byte) ([]Built, error)

Build writes the .xlsx files: per edition the blank template and, when the workbook has an example, the filled example. Files build side by side; previous returns a file built from the same inputs before, stamped with its key, which is used as is.

func (Report) Compat

func (r Report) Compat(ctx context.Context, office string, files []Built) ([]string, error)

Compat recalculates the built files in LibreOffice and returns where its values differ from lfm's.

func (Report) Excel

func (r Report) Excel(built []Built) ([]string, error)

Excel opens every file in Microsoft Excel for Mac, recalculates it and holds Excel's values to lfm's: the differences, or why Excel refused a file.

func (Report) Facts

func (r Report) Facts() []string

Facts are the workbook's numbers for the shop descriptions, from the build.

func (Report) FileName

func (r Report) FileName(e Edition, example bool) string

FileName is the .xlsx name of an edition, blank or example.

func (Report) FileNote

func (r Report) FileNote(name string) string

FileNote is the line under a file on the download page.

func (Report) Images

func (r Report) Images() []ImagePlan

Images plans the listing images from the first edition's example: the main report alone first (Etsy ranks it higher without text), every tab, each tab large, then what it works with.

func (Report) Preview

func (r Report) Preview(key string) []byte

Preview is an edition as one HTML page with its tabs, computed with the example (or the blank template), for lfm serve.

func (Report) Slug

func (r Report) Slug() string

Slug is the file name stem of the product.

func (Report) StartDoc

func (r Report) StartDoc(ed *edition) []byte

StartDoc is the start-here PDF of an edition as HTML to print: the copy button first, the steps from the guide sheet, the notes for Excel, Numbers and phones, the licence.

func (Report) StartDocs

func (r Report) StartDocs() map[string][]byte

StartDocs are the start PDFs to print, by file name.

func (Report) StartFileName

func (r Report) StartFileName(e Edition) string

StartFileName is the start PDF of an edition.

type Row

type Row map[string]any

Row is one row of a dataset or seed: column key -> value. Text values may be localized.

type Sheet

type Sheet struct {
	Key     string    `json:"key"` // stable name for placeholders: [log.amount]
	Name    Text      `json:"name"`
	Kind    string    `json:"kind"` // guide, form, table or report
	Hidden  bool      `json:"hidden"`
	Lines   []Text    `json:"lines"`   // guide: one per row; "# " starts a heading
	Cells   []Cell    `json:"cells"`   // form and report
	Columns []Column  `json:"columns"` // table
	Rows    int       `json:"rows"`    // table: how many data rows the template holds
	Seed    []Row     `json:"seed"`    // table: rows the blank template ships with, such as categories
	Charts  []Chart   `json:"charts"`  // report
	Widths  []float64 `json:"widths"`  // report: column widths in characters, from column A
}

Sheet is one tab.

type Summary

type Summary struct {
	Name     string   `json:"name,omitempty"`
	Concept  bool     `json:"concept"`
	Workbook bool     `json:"workbook"`
	Editions []string `json:"editions,omitempty"`
	Sheets   int      `json:"sheets"`
	Formulas int      `json:"formulas"` // formula cells per edition
	Checked  []string `json:"checked,omitempty"`
	Sell     string   `json:"sell"`
	URL      string   `json:"url,omitempty"`
	Files    []string `json:"files,omitempty"`
	Listing  bool     `json:"listing"`
	Linked   int      `json:"linked"` // Google Sheets masters linked
	Channels []string `json:"channels,omitempty"`
	Images   int      `json:"images"`
	Pending  bool     `json:"pending"`
	Compat   string   `json:"compat,omitempty"`
}

Summary is what the report and --json show about the spreadsheet.

type Tab

type Tab struct {
	Key, Job string
	Line     int
}

Tab is one planned sheet, by its key in workbook.json.

type Text

type Text struct {
	One    string
	ByLang map[string]string
}

Text is a string, or one per language: {"en": "Log", "de": "Buchungen"}.

func (Text) Empty

func (t Text) Empty() bool

Empty reports whether the text has nothing in any language.

func (Text) In

func (t Text) In(lang string) string

In picks the text for a language: its own, else English, else any.

func (Text) Missing

func (t Text) Missing(langs []string) []string

Missing names the languages among langs the text has no entry for.

func (*Text) UnmarshalJSON

func (t *Text) UnmarshalJSON(b []byte) error

UnmarshalJSON takes a string or an object of strings.

type TextList

type TextList struct {
	One    []string
	ByLang map[string][]string
}

TextList is a list of strings, or one list per language.

func (TextList) In

func (t TextList) In(lang string) []string

In picks the list for a language.

func (*TextList) UnmarshalJSON

func (t *TextList) UnmarshalJSON(b []byte) error

UnmarshalJSON takes a list or an object of lists.

type Workbook

type Workbook struct {
	Editions []Edition                 `json:"editions"`
	Today    string                    `json:"today"` // the date TODAY() is evaluated at in checks and previews
	Words    map[string]Text           `json:"words"` // localized words formulas and choices use as [@key] and "@key"
	Sheets   []Sheet                   `json:"sheets"`
	Datasets map[string]Dataset        `json:"datasets"` // "example" fills the example file; "empty" is the blank template
	Expect   map[string]map[string]any `json:"expect"`   // dataset -> cell -> value
}

Workbook is deliverables/spreadsheet/workbook.json: the sheets of the product, its editions, the datasets it is checked with and what they must compute.

Jump to

Keyboard shortcuts

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