Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_file/dev/xlsx_oracle.sh

2.1 KiB, 1 run, executable

created by r1870400018:22735, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#!/usr/bin/env bash
2# Puts a .xlsx this crate wrote to an external reader, and says what came back.
3#
4# A spreadsheet is the format where reading your own output proves least. The things that separate it
5# from a table -- a string that lives in another part, a date that is only a date because a style says
6# so, a formula whose cached value is what everyone sees -- are all CONVENTIONS rather than structure,
7# so a file can satisfy this crate's own reader completely and still open in Excel as five columns of
8# five-digit integers.
9#
10# LibreOffice is the second opinion. It is not Excel, and where the two disagree the right answer is
11# unknown and the right response is to preserve rather than to choose. But it is somebody else's
12# implementation, which is the only kind of evidence there is here.
13#
14# fe2o3_file/dev/xlsx_oracle.sh
15#
16# Needs `soffice` on the path.
17
18set -eu
19
20work="$(mktemp -d "${XDG_CACHE_HOME:-$HOME/.cache}/xlsx-oracle.XXXXXX")"
21trap 'rm -rf "$work"' EXIT
22
23root="$(cd "$(dirname "$0")/../.." && pwd)"
24target="${CARGO_TARGET_DIR:-$HOME/.cache/cargo-targets/${RC_SLOT:-solo}/fe2o3}"
25
26CARGO_TARGET_DIR="$target" cargo run -q -p oxedyne_fe2o3_file --example make_xlsx \
27 --manifest-path "$root/Cargo.toml" -- "$work/made.xlsx"
28
29echo "-- the archive --"
30unzip -t "$work/made.xlsx"
31
32echo "-- what LibreOffice made of the cells --"
33HOME="$work" soffice --headless --convert-to csv --outdir "$work" "$work/made.xlsx" >/dev/null
34cat "$work/made.csv"
35
36echo "-- and of the things a CSV cannot show --"
37HOME="$work" soffice --headless --convert-to fods --outdir "$work" "$work/made.xlsx" >/dev/null
38echo -n "sheets: "; grep -o 'table:name="[^"]*"' "$work/made.fods" | tr '\n' ' '; echo
39echo -n "formulas: "; grep -o 'table:formula="[^"]*"' "$work/made.fods" | tr '\n' ' '; echo
40echo -n "types: "; grep -o 'office:value-type="[^"]*"' "$work/made.fods" \
41 | sort | uniq -c | tr '\n' ' '; echo
42# A date that arrives as `float` is the whole failure this file exists to catch: it means the number
43# reached the reader and the style that made it a date did not.
44echo -n "dates: "; grep -o 'office:date-value="[^"]*"' "$work/made.fods" | tr '\n' ' '; echo