Files
spring-boot-demo/excel-export/scripts/libreoffice-check.sh
T

27 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Opens the same 40-row report from the XSSF and the SXSSF endpoint in headless LibreOffice, and reports what it does.
# Needs: soffice, python3, curl, a built jar. Microsoft Excel itself was NOT available for this check.
cd "$(dirname "$0")/.."
d=$(mktemp -d); P="file://$d/profile"
java -jar target/excel-export-1.0.0.jar --server.port=38091 >/dev/null 2>&1 & p=$!
for _ in $(seq 1 120); do [ "$(curl -s localhost:38091/probe/ping)" = ok ] && break; sleep 1; done
curl -s -o "$d/xssf.xlsx" "localhost:38091/export/xssf?rows=40"
curl -s -o "$d/sxssf.xlsx" "localhost:38091/export/sxssf?rows=40"
kill $p; wait $p 2>/dev/null || true
python3 - "$d" <<'PY'
import sys, zipfile
d = sys.argv[1]
with zipfile.ZipFile(d + "/sxssf.xlsx") as z, zipfile.ZipFile(d + "/rezipped.xlsx", "w", zipfile.ZIP_DEFLATED) as out:
for n in z.namelist():
out.writestr(n, z.read(n))
for f in ("xssf", "sxssf"):
with zipfile.ZipFile(f"{d}/{f}.xlsx") as z:
print(f"{f}.xlsx ZIP entry timestamps: {sorted({i.date_time for i in z.infolist()})}")
PY
echo "$(soffice --version 2>/dev/null | head -1)"
for f in xssf sxssf rezipped; do
(cd "$d" && timeout 120 soffice --headless "-env:UserInstallation=$P" --convert-to csv "$f.xlsx" >/dev/null 2>&1)
if [ -f "$d/$f.csv" ]; then echo "$f.xlsx: LibreOffice loads it; row 2 -> $(sed -n 2p "$d/$f.csv")"; else echo "$f.xlsx: LibreOffice: source file could not be loaded"; fi
done
rm -rf "$d"