Documentation
¶
Overview ¶
Package sheet reads and writes the spreadsheets APIs upload and export: CSV, and XLSX (Office Open XML). A cell is the text of its value; an XLSX cell also has a type, a number format and a formula (Cell), and the rest of a workbook (styles, the worksheets apart from their cells) is kept to be compared as it is.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsPartLike ¶
IsPartLike reports whether a bare name in a path is in the form of a part name (sheet1), which paths no longer use (PathName).
func Refs ¶
Refs lists the references of the cells of both sheets, with a value or only a formula or a style (Meta), row by row and column by column.
func WriteWorkbook ¶
WriteWorkbook writes a workbook with a worksheet for each of sheets, in that order, holding the rows as text cells; the n-th one is the part xl/worksheets/sheet<n>.xml. Like WriteXLSX, the same sheets give the same bytes.
Types ¶
type Cell ¶
type Cell struct {
// Type is the type of the value: number, string, bool, error or date.
// A shared, inline and formula string are all string: how a writer
// stores a text is not its type.
Type string
// Format is the number format: its format code, "builtin N" for a
// built-in format the workbook does not write out, "" for General.
Format string
// Formula is the formula's text without "=" (of a shared formula, the
// text of the cell that defines it); "" for a plain value.
Formula string
// Style is the index of the cell's style (font, fill, borders and the
// number format) in the workbook's styles; "" for the default.
Style string
}
Cell is what an XLSX cell has besides the text of its value.
type Sheet ¶
type Sheet struct {
// Name is the name the workbook gives the worksheet ("Users"), or
// its part name ("sheet1") when the workbook does not name it (Named
// false); "csv" for a CSV file.
Name string
Named bool
Cells map[string]string
// Meta holds what an XLSX cell has besides its value, for every cell
// in Cells and every empty cell with a formula or a style of its own
// (a cell without a value is not in Cells); nil for a CSV file.
Meta map[string]Cell
// Rich holds how the rich texts (a shared or inline string of runs in
// a bold font, a color) are formatted, by cell: each run as <r len="N">,
// its length in characters, with its properties; nil when no cell has
// one. Kept apart from Meta, which every cell has.
Rich map[string]string
}
Sheet is one worksheet: cell reference (A1) → value.
func ReadCSV ¶
ReadCSV reads a CSV file (a UTF-8 byte order mark is skipped). Empty cells are left out, as in a spreadsheet.
func (Sheet) PathName ¶
PathName writes the worksheet in a drift or rule path (xlsx:<PathName>!B2). A name of letters, digits, _ and . stands as it is; any other is quoted as in a spreadsheet formula, with a quote inside doubled:
Users Članovi 'Q1 2026!' 'O''Brien' 'sheet1' [sheet1]
A worksheet the workbook does not name is its part name in brackets, [sheet1], which no workbook name can be ([ and ] are not allowed in one). A name written like a part name (sheet1) is quoted too: that bare form is what DriftGate wrote before it read the workbook's names, and is never written now.
type Workbook ¶
type Workbook struct {
Sheets []Sheet
// Rest is the workbook apart from its cells, by part name in order:
// every part but the document properties (docProps/: times, author,
// application), the shared strings and the calculation chain (both
// follow from the cells), with the worksheets written without their
// cells (withoutValues). Two workbooks with the same cells and the same
// Rest look the same in a spreadsheet application.
Rest []Part
}
Workbook is a read XLSX file: its worksheets, and the rest of it.
func ReadWorkbook ¶
ReadWorkbook reads the cells of every worksheet, in the order of the workbook's tabs and under the names the workbook gives them. When the workbook does not say which part holds which worksheet (xl/workbook.xml or its relationships are missing, cannot be read, or point at a part that is not there), every worksheet part is read in the order of its number and named after it (sheet1, Named false): one rule for the whole workbook, so a damaged workbook never mixes the two. Shared strings and inline strings are resolved; a number, boolean or formula result is the text stored in the cell. A row or cell without its optional reference (r) is where ECMA-376 puts it: the row after the previous row, the column after the previous cell of the row.