Documentation
¶
Overview ¶
Package tablexlsx writes an Excel workbook from a workbook described as data (#1849): named sheets of columns and rows, a small vocabulary of column types, and the few presentation facts a report needs -- a bold header row, column widths, a frozen pane and an optional title row. It is deliberately not a styling API: a sheet says what its columns ARE, and the writer decides how each type is shown.
Numbers the script computed exactly stay exact. A currency or decimal cell is written from its decimal text into the cell's value, so "1234.50" is the number the file carries, not the nearest float64 to it. See cells.go.
Index ¶
Constants ¶
const ( // MaxSheets bounds the sheets of one workbook. Excel has no fixed limit; // a workbook with more sheets than this is several outputs. MaxSheets = 255 // MaxCells bounds the cells of one workbook, across its sheets. The // writer holds the workbook in memory while it builds it, so the bound is // on what is built, not only on the bytes the result compresses to. MaxCells = 2_000_000 )
Limits a workbook is held to before a byte is written.
const ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
ContentType is the media type of an Excel workbook.
const Extension = ".xlsx"
Extension is the file extension of an Excel workbook.
Variables ¶
This section is empty.
Functions ¶
func CheckSheetName ¶
CheckSheetName holds a sheet name to Excel's rules: 1 to 31 characters (UTF-16 units, as Excel counts them), none of []:*?/\, not beginning or ending with an apostrophe, and no character Excel cannot store.
Types ¶
type ColumnType ¶
type ColumnType string
ColumnType is one entry of the vocabulary a sheet's column_types uses.
const ( TypeString ColumnType = "string" TypeInteger ColumnType = "integer" TypeDecimal ColumnType = "decimal" TypeCurrency ColumnType = "currency" TypeDate ColumnType = "date" TypeDateTime ColumnType = "datetime" TypePercent ColumnType = "percent" )
The column types a sheet may declare. A column that declares none is written from its values: text as text, a number as a number, a bool as a bool.
type Sheet ¶
type Sheet struct {
Name string
Title string
Columns []string
// Types is the declared type of each column that declared one.
Types map[string]ColumnType
// Widths is the declared width of each column that declared one, in
// Excel's character units.
Widths map[string]float64
// Freeze is the top-left cell of the scrolling pane, "" for none.
Freeze string
// Rows holds each row's values, positional against Columns.
Rows [][]any
}
Sheet is one sheet of a workbook: its columns in order, each row's values in that order, and the presentation facts it declared.
type SheetShape ¶
SheetShape is what a report says about one sheet: its name and how many data rows it holds (the header and title rows are not counted).
type Workbook ¶
type Workbook struct {
Sheets []Sheet
}
Workbook is a parsed, validated workbook description.
func Parse ¶
Parse reads a workbook description: a map with one key, "sheets", a list of sheet maps. Values are the plain Go values a JSON decode or a script's conversion produces (string, int64, float64, bool, nil, []any, map[string]any).
columnsFor supplies the column order for a sheet whose description names no "columns": the caller that still holds the rows in their written order (a script's dicts keep insertion order; a Go map does not) reads it there. It may be nil, in which case such a sheet is refused.
func (*Workbook) Shape ¶
func (w *Workbook) Shape() []SheetShape
Shape reports each sheet's name and data row count, in order.