CLI Reference

The wb CLI reads, writes, and manipulates Excel files from the terminal.

Installation

go install github.com/jpoz/werkbook/cmd/wb@latest

Global Flags

FlagDefaultDescription
--formatjsonOutput format: json, markdown, or csv

Commands

info

Show sheet metadata — dimensions, cell counts, and data ranges.

wb info report.xlsx
wb info --sheet Sales report.xlsx

Flags:

FlagDefaultDescription
--sheetall sheetsFilter to a specific sheet

Example output:

{
  "ok": true,
  "command": "info",
  "data": {
    "file": "report.xlsx",
    "sheets": [
      {
        "name": "Sales",
        "max_row": 100,
        "max_col": 5,
        "max_col_letter": "E",
        "non_empty_cells": 450,
        "has_formulas": true,
        "data_range": "A1:E100"
      }
    ]
  }
}

read

Read cell data from a sheet.

wb read report.xlsx
wb read --sheet Sales --range A1:D10 report.xlsx
wb read --headers --format markdown report.xlsx
wb read --include-formulas --include-styles report.xlsx

Flags:

FlagDefaultDescription
--sheetfirst sheetSheet name to read
--rangefull sheetA1 range notation (e.g. A1:D10)
--include-formulasfalseInclude formula strings in output
--include-stylesfalseInclude style objects in output
--headersfalseTreat first row as column headers

The markdown and csv formats output raw table data directly (no JSON envelope).


edit

Apply changes to an existing workbook using a JSON patch array.

# Patch from flag
wb edit --patch '[{"cell":"A1","value":"Updated"}]' report.xlsx

# Patch from stdin
cat patch.json | wb edit report.xlsx

# Save to a different file
wb edit --output new.xlsx --patch '[{"cell":"A1","value":"Hello"}]' report.xlsx

# Preview changes without saving
wb edit --dry-run --patch '[{"cell":"A1","value":"Test"}]' report.xlsx

Flags:

FlagDefaultDescription
--sheetfirst sheetDefault sheet for operations
--patchstdinJSON array of patch operations
--outputoverwrite inputSave to a different file path
--dry-runfalseApply in memory without saving

Patch operations:

Each element in the patch array is a JSON object. All fields are optional except cell (or row for row operations).

[
  {"cell": "A1", "value": "Hello"},
  {"cell": "B1", "value": 42},
  {"cell": "C1", "formula": "A1&B1"},
  {"cell": "A1", "style": {"font": {"bold": true}}},
  {"cell": "A", "column_width": 20.0},
  {"row": 1, "row_height": 30.0},
  {"add_sheet": "NewSheet"},
  {"delete_sheet": "OldSheet"}
]
FieldTypeDescription
cellstringCell reference ("A1"), column letter ("B"), or range ("A1:D1")
rowintRow number (for row_height)
sheetstringTarget sheet (defaults to --sheet flag)
valueanyCell value (null clears the cell)
formulastringFormula string (e.g. "SUM(B2:B3)")
styleobjectStyle object (see below)
column_widthnumberColumn width (use cell as column letter)
row_heightnumberRow height (use row as row number)
add_sheetstringCreate a new sheet
delete_sheetstringDelete a sheet

create

Create a new workbook from a JSON spec.

# Spec from flag
wb create --spec '{"sheets":["Data"],"cells":[{"cell":"A1","value":"Hello"}]}' out.xlsx

# Spec from stdin
cat spec.json | wb create out.xlsx

Flags:

FlagDefaultDescription
--specstdinJSON spec for the new workbook

Spec format:

{
  "sheets": ["Sheet1", "Sheet2"],
  "cells": [
    {"cell": "A1", "sheet": "Sheet1", "value": "Name"},
    {"cell": "B1", "sheet": "Sheet1", "formula": "SUM(B2:B10)"}
  ]
}

The cells array uses the same format as edit patch operations.


calc

Force-recalculate all formulas and return the results.

wb calc report.xlsx
wb calc --range A1:D10 report.xlsx
wb calc --output recalculated.xlsx report.xlsx

Flags:

FlagDefaultDescription
--sheetfirst sheetSheet to read results from
--rangefull sheetA1 range to return
--outputdon’t saveSave recalculated workbook to this path

Output uses the same format as read, but always includes formula strings.


formula list

List all registered formula functions.

wb formula list

Example output:

{
  "ok": true,
  "command": "formula",
  "data": {
    "functions": ["ABS", "AND", "AVERAGE", "..."],
    "count": 55
  }
}

version

Print version information.

wb version

Output Format

All JSON output uses a consistent envelope:

{
  "ok": true,
  "command": "read",
  "data": { ... }
}

Errors are written to stderr:

{
  "ok": false,
  "command": "read",
  "error": {
    "code": "FILE_NOT_FOUND",
    "message": "file does not exist",
    "hint": "check the file path"
  }
}

Exit Codes

CodeMeaning
0Success
1File I/O error
2Validation error
3Partial failure (some operations succeeded)
4Usage/argument error

Style JSON

Styles in edit and read output use this structure:

{
  "font": {
    "name": "Calibri",
    "size": 11,
    "bold": true,
    "italic": false,
    "underline": false,
    "color": "FF0000"
  },
  "fill": {"color": "FFFF00"},
  "border": {
    "top": {"style": "thin", "color": "000000"},
    "bottom": {"style": "medium", "color": "000000"},
    "left": {"style": "thin", "color": "000000"},
    "right": {"style": "thin", "color": "000000"}
  },
  "alignment": {
    "horizontal": "center",
    "vertical": "top",
    "wrap_text": true
  },
  "num_fmt": "#,##0.00"
}

Border styles: "thin", "medium", "thick", "dashed", "dotted", "double"