Building, traversing and editing PSOSF archives as Clojure data.
Every function is pure: it takes an archive (or a worksheet) and returns a new one. Nothing here touches files or JSON; use psosf.core to read, write and classify.
Cell content is {:kind :text :text "..."} or {:kind :formula :text "=..."}. Wherever content is accepted, a plain string is taken as text and (formula "=A1+1") builds a formula. Values are kept as text, as PSOSF stores them.
The manifest stays a map with string keys, exactly as in manifest.json, so an archive always writes back in canonical form.
(-> (archive "Account Balances" {:namespace "com.example.ledger"}) (add-sheet (-> (sheet "Accounts") (add-column {:header "id" :type "text"}) (add-column {:header "amount" :type "number" :annotation ["Balance in US dollars."]}) (add-column {:header "negative" :type "boolean" :annotation ["pebblestream:fail"]}) (add-row ["1" "435" (formula "=B2<0")]))))
Building, traversing and editing PSOSF archives as Clojure data.
Every function is pure: it takes an archive (or a worksheet) and returns a
new one. Nothing here touches files or JSON; use psosf.core to read, write
and classify.
Cell content is {:kind :text :text "..."} or {:kind :formula :text "=..."}.
Wherever content is accepted, a plain string is taken as text and
(formula "=A1+1") builds a formula. Values are kept as text, as PSOSF stores
them.
The manifest stays a map with string keys, exactly as in manifest.json, so
an archive always writes back in canonical form.
(-> (archive "Account Balances" {:namespace "com.example.ledger"})
(add-sheet (-> (sheet "Accounts")
(add-column {:header "id" :type "text"})
(add-column {:header "amount" :type "number"
:annotation ["Balance in US dollars."]})
(add-column {:header "negative" :type "boolean"
:annotation ["pebblestream:fail"]})
(add-row ["1" "435" (formula "=B2<0")]))))(add-annotation-line sheet header line)Appends one line (a directive or a comment) to a column's annotation.
Appends one line (a directive or a comment) to a column's annotation.
(add-column sheet spec)Adds a column at the end (or at :index). Existing rows get an empty cell.
Adds a column at the end (or at :index). Existing rows get an empty cell.
(add-row sheet values)Appends a row: a vector of values in column order, or a map of header to value. Missing values are empty.
Appends a row: a vector of values in column order, or a map of header to value. Missing values are empty.
(add-sheet archive sheet)Adds a worksheet at the end. Throws if the name is taken.
Adds a worksheet at the end. Throws if the name is taken.
(archive name)(archive name {:keys [namespace description license]})A new, empty version 1.1 archive. Options: :namespace, :description, :license {:name :url :spdx}.
A new, empty version 1.1 archive. Options: :namespace, :description,
:license {:name :url :spdx}.(assoc-manifest archive k v)Sets a manifest value. "format", "format-version" and "sheets" are managed by the archive and cannot be set.
Sets a manifest value. "format", "format-version" and "sheets" are managed by the archive and cannot be set.
(cell sheet row header)Content at a zero-based data row and a header, or nil.
Content at a zero-based data row and a header, or nil.
(column {:keys [header type annotation style] :or {type "text"}})A column. :annotation is a list of lines: strings beginning with pebblestream: are directives, other strings are comments.
A column. :annotation is a list of lines: strings beginning with pebblestream: are directives, other strings are comments.
(column-index sheet header)The zero-based index of the column with this header, or nil.
The zero-based index of the column with this header, or nil.
(comments sheet)Every comment line in the worksheet's annotations.
Every comment line in the worksheet's annotations.
(directives sheet)Every directive line in the worksheet's annotations: ({:column "amount" :text "pebblestream:fail"} ...).
Every directive line in the worksheet's annotations:
({:column "amount" :text "pebblestream:fail"} ...).(find-sheet archive name)The worksheet with this name, or nil.
The worksheet with this name, or nil.
(formula text)Formula content. text must begin with =.
Formula content. text must begin with =.
(formulas sheet)Every formula cell: ({:row 0 :column "negative" :text "=B2<0"} ...). :row is zero-based over data rows; in Excel it is row (+ row 2).
Every formula cell: ({:row 0 :column "negative" :text "=B2<0"} ...).
:row is zero-based over data rows; in Excel it is row (+ row 2).(manifest-get archive k)A manifest value by key, e.g. (manifest-get a "namespace").
A manifest value by key, e.g. (manifest-get a "namespace").
(rename-sheet archive old-name new-name)Renames a worksheet. References to it inside formulas and directives are not rewritten.
Renames a worksheet. References to it inside formulas and directives are not rewritten.
(row-values sheet)Rows as maps of header to text: a value's text, or a formula's text.
Rows as maps of header to text: a value's text, or a formula's text.
(rows sheet)Rows as maps of header to content.
Rows as maps of header to content.
(set-annotation sheet header lines)Replaces a column's annotation with these lines (strings or line maps).
Replaces a column's annotation with these lines (strings or line maps).
(set-cell sheet row header value)Sets the content at a zero-based data row and a header.
Sets the content at a zero-based data row and a header.
(set-license archive license)Sets the license: {:name "Apache License 2.0" :url "..." :spdx "Apache-2.0"}.
Sets the license: {:name "Apache License 2.0" :url "..." :spdx "Apache-2.0"}.
(sheet name)A new worksheet with no columns.
A new worksheet with no columns.
(update-column sheet header f & args)Applies f to the column map with this header.
Applies f to the column map with this header.
(update-sheet archive name f & args)Applies f (and args) to the named worksheet.
Applies f (and args) to the named worksheet.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |