.xlsx library for Go.

Read, write, and recalculate .xlsx workbooks in Go. Open existing files, create new ones, set values and formulas, and save the result back to disk.

Install

Add the module to a Go project and start working with workbooks, sheets, cells, and formulas.

go modules
go get github.com/jpoz/werkbook
main.go zero external deps
package main

import "github.com/jpoz/werkbook"

func main() {
    f := werkbook.New()
    s := f.Sheet("Summary")

    s.SetValue("A1", "Revenue")
    s.SetValue("B1", 583200)
    s.SetFormula("B2", "B1*0.12")

    f.Recalculate()
    f.SaveAs("report.xlsx")
}
Dependencies
0 external
Formula engine
Compiled
Cell model
Typed values
Storage
Sparse rows
Workbook model

Sparse workbook storage and dependency tracking.

map-backed incremental recalc

The workbook model stores only the sheets, rows, and cells you touch. Formula dependencies are tracked separately so recalculation can follow the affected cells.

Go types

Workbooks, sheets, rows, and cells map directly to Go structs and maps.

Dependency graph

Formula references are stored in a dependency graph so the engine can find which formulas need recalculation after a change.

Recalculation

Writes mark dependent formulas dirty, and values can be resolved lazily or through Recalculate().

type DepGraph struct {
  dependsOn  map[QualifiedCell]map[QualifiedCell]bool
  dependents map[QualifiedCell]map[QualifiedCell]bool
  rangeSubs  []rangeSub
}

Read, write, and recalculate .xlsx files.

Open existing workbooks, create new ones, set cell values and formulas, evaluate results, and write OOXML files from Go.

AST formula compiler

Built-in formula engine

Formulas are lexed, parsed, compiled, dependency-sorted, and evaluated in Go. The project currently includes 198 built-in functions.

tokens → parser → AST → dependency graph → evaluator
MAP sparse storage

Sparse workbook storage

Rows and cells are stored as maps, so a workbook with data in A1 and Z10000 does not allocate the whole rectangle between them.

cells["A1"] = "Revenue"
cells["Z10000"] = 42
TYPE value model

Typed cell values

Numbers, strings, booleans, errors, and empty cells keep their type in the workbook model and formula engine.

Number String Bool Error Empty
ZIP/XML OOXML package

OOXML read and write

Open existing .xlsx files, change sheets and cells, and write them back without Excel or another spreadsheet runtime.

ZIP/XML → workbook model → update cells → ZIP/XML

The API follows spreadsheet concepts

The main types are workbooks, sheets, rows, cells, formulas, and file operations.

Create
f := werkbook.New()
s := f.Sheet("Summary")
s.SetValue("A1", "Revenue")
s.SetValue("B1", 583200)
s.SetFormula("B2", "B1*0.12")
f.SaveAs("report.xlsx")
Inspect
f, _ := werkbook.Open("report.xlsx")
s := f.Sheet("Summary")
v, _ := s.GetValue("B2")
fmt.Println(v.Raw())

Formula recalculation is explicit

Formulas are parsed, compiled, dependency-ordered, and then evaluated when you recalculate a workbook.

lexer
parser
compiler
dependency sort
evaluator

Cell values stay typed

The library keeps spreadsheet value types visible in code instead of flattening everything to strings.

Number
String
Bool
Error

Zero external dependencies

No CGo, no system packages, and no spreadsheet runtime. It stays inside a normal Go build.

module github.com/jpoz/werkbook
require (
  // none
)

Open and update existing workbooks

Load an existing .xlsx file, update values or formulas, and write it back through OOXML ZIP/XML serialization.

Open existing workbooks
Change sheets, cells, and formulas
Save back to .xlsx

Create a workbook in three steps.

Install the module, set values and formulas, then recalculate and save the workbook as .xlsx.

01

Install the module

Add the package to an existing project with one command.

go get github.com/jpoz/werkbook
02

Set values and formulas

Use workbook, sheet, and cell methods directly in Go.

03

Recalculate and save

Trigger formula evaluation, then write a real .xlsx file back to disk.

quick-start.go minimal example
package main

import "github.com/jpoz/werkbook"

func main() {
    f := werkbook.New()
    s := f.Sheet("Sheet1")

    s.SetValue("A1", "Hello")
    s.SetFormula("B1", "LEN(A1)")

    f.Recalculate()
    f.SaveAs("output.xlsx")
}