Skip to content
Spreadsheet

Spreadsheet

A workbook holds sheets, a sheet holds rows, and a row holds cells. You get each level from the one above, and cells are addressed within their row rather than by absolute coordinates:

ss := spreadsheet.New()
sheet := ss.AddSheet()
row := sheet.AddRow()
row.AddCell().SetString("Hello")

Formatting lives in shared cell styles on the workbook rather than on individual cells, so a large sheet holds a few styles and many references to them. A formula’s text and its computed value are stored separately, so writing a formula calculates nothing until something evaluates it.

Validation is the other habit worth picking up. Validate() catches structural problems before you write the file, which is a great deal easier than working out why Excel is refusing to open the result.

Build a workbook

SectionCovers
Simple SpreadsheetThe shortest complete program. Start here.
Complex SpreadsheetA worked example combining several features.
CellsBorders, shading, number formats, merging, rotation, comments.
Rows and ColumnsInserting, removing, freezing, sorting and filtering.
FormulasSetting, evaluating, flattening, and named references.
ChartsEvery chart type, one guide each.
ImagesPlacing and extracting pictures.
Format as TableTurning a range into a styled Excel table.

Read and output

SectionCovers
Text ExtractionReading cell content back out.
Validate a WorkbookCatching structural problems before writing.
Convert to PDFRendering sheets to PDF.
Last updated on