Code: CSV and spreadsheets in Jennifer
CSV and spreadsheets: the code
The programs behind the slides, for Jennifer 0.27.0. The CSV part uses the bundled csv.j module; the spreadsheet part uses the @deckyard/sheets deck listed in deck.toml, so run jvc install once in this folder to fill vendor/. No server is needed. Run everything from this folder: the programs read and write their files by relative path.
sales.csv: the till export, with a comment line,;separators, quoted fields and padding ("A real export").bad.csv: the same with two broken records.parse.j:csv.parseon RFC 4180 input, and the errors for a short record, a stray quote and text after a closing quote ("csv.parse: RFC 4180", "Strict: a broken file is an error"). Run:jennifer run parse.jdialect.j: a dialect with;,#comments and trimming, written back as plain CSV ("A dialect for the file"). Run:jennifer run dialect.jstream.j: a streaming reader that skips the bad records ofbad.csv("Streaming, and reading past bad records"). Run:jennifer run stream.jaggregate.j: records, revenue per branch, andformatSafeagainst formula injection ("Records, cleaning, totals", "Writing CSV for a spreadsheet: formatSafe"). Run:jennifer run aggregate.jbuild.j: builds the "Week 44" sheet fromsales.csvwith formulas, a number format and bold headers, recalculates and savesweek44.xlsx("Building the sheet", "Number formats and styles", "Recalculate and save as XLSX"). Run:jennifer run build.jreadback.j: opensweek44.xlsxand reads the total's formula, cached value and display text ("Reading it back"). Run afterbuild.j:jennifer run readback.jerrors.j:#DIV/0!as a value, a malformed formula, the nesting cap (kind"limit") and a file that is not a ZIP; writesfake.xlsx("Errors: values and throws"). Run afterbuild.j:jennifer run errors.jsheetnames.j: a reference to a missing sheet is#REF!in a formula and a throw from the API ("Errors: values and throws"). Run afterbuild.j:jennifer run sheetnames.jmakeyear.j: writesyear.xlsx, a 20,001-row sheet for the streaming slide. Run:jennifer run makeyear.jstreamsheet.j: readsyear.xlsxrow by row and sums a column ("Streaming a large sheet"). Run aftermakeyear.j:jennifer run streamsheet.jexport.j: writes the sheet asweek44.html,week44.jsonlandweek44.pdf("Export: HTML, JSON, PDF"). Run afterbuild.j:jennifer run export.j
| File | Size | |
|---|---|---|
| LICENSE | 899 B | raw |
| README.md | 2.4 KiB | raw |
| aggregate.j | 749 B | raw |
| bad.csv | 100 B | raw |
| build.j | 1.5 KiB | raw |
| deck.toml | 257 B | raw |
| dialect.j | 274 B | raw |
| errors.j | 616 B | raw |
| export.j | 366 B | raw |
| makeyear.j | 352 B | raw |
| parse.j | 374 B | raw |
| readback.j | 373 B | raw |
| sales.csv | 173 B | raw |
| sheetnames.j | 387 B | raw |
| stream.j | 299 B | raw |
| streamsheet.j | 424 B | raw |