mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-16 19:09:59 -06:00
Compare commits
26
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d86924dd10 | ||
|
|
904c39e104 | ||
|
|
abcfc19153 | ||
|
|
3ca81a761b | ||
|
|
1476d4e7ab | ||
|
|
91f153de5b | ||
|
|
3443e06bfc | ||
|
|
e1147239fc | ||
|
|
ef99f1e51f | ||
|
|
19f07f3a25 | ||
|
|
407e0e1fa9 | ||
|
|
dbdec081e2 | ||
|
|
44050e9447 | ||
|
|
f22b4ed9dd | ||
|
|
d593a8f99d | ||
|
|
bfcb3a515a | ||
|
|
da46633db7 | ||
|
|
b01be008a0 | ||
|
|
4ea6f081d7 | ||
|
|
569707e3f0 | ||
|
|
bece357298 | ||
|
|
de3576286e | ||
|
|
dc9066cae0 | ||
|
|
d2c7c6ec58 | ||
|
|
713a66e0d3 | ||
|
|
07fcccd855 |
@@ -121,3 +121,7 @@ People trust GridCraft with their numbers; a crash loses their work. **This outr
|
||||
- Some workflow files here still run their own jobs. Don't add to them. Moving a job into craft-common-actions is its own task, never part of another PR, and the job stays here until a shared workflow runs it.
|
||||
|
||||
New workspace crates include `workspace = true` under `[lints]` in `Cargo.toml`. Production crate roots declare the crate-level lint attributes before modules; crate-level `//!` documentation may precede them.
|
||||
|
||||
## Shared libraries
|
||||
|
||||
Before adding or changing file-format, codec, protocol, or reusable UI code, check `storytold/craft-libs` and its open PRs first; reuse or extend the shared library rather than duplicating it locally, keep app-specific policy and model mapping in the app, and preserve behavior, security/resource limits, attribution, and regression coverage during cutovers.
|
||||
|
||||
Generated
+18
@@ -937,6 +937,16 @@ name = "craft-fonts-build"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9"
|
||||
|
||||
[[package]]
|
||||
name = "craft-gridcraft-format"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=9a6d894200221fcfedc274870c30394d404f859d#9a6d894200221fcfedc274870c30394d404f859d"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-i18n"
|
||||
version = "0.1.0"
|
||||
@@ -988,6 +998,11 @@ dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-pdf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=bc358686389892a3827e64fc26bedc278ef1e299#bc358686389892a3827e64fc26bedc278ef1e299"
|
||||
|
||||
[[package]]
|
||||
name = "craft-print"
|
||||
version = "0.1.0"
|
||||
@@ -2215,6 +2230,7 @@ name = "gridcraft-engine"
|
||||
version = "0.19.1"
|
||||
dependencies = [
|
||||
"craft-csv",
|
||||
"craft-gridcraft-format",
|
||||
"gridcraft-calc",
|
||||
"gridcraft-chart",
|
||||
"gridcraft-core",
|
||||
@@ -2295,6 +2311,7 @@ dependencies = [
|
||||
name = "gridcraft-pdf"
|
||||
version = "0.19.1"
|
||||
dependencies = [
|
||||
"craft-pdf",
|
||||
"craft-stream-codecs",
|
||||
"harfrust",
|
||||
"sha2 0.11.1",
|
||||
@@ -2368,6 +2385,7 @@ dependencies = [
|
||||
"craft-offcrypto",
|
||||
"craft-opc",
|
||||
"craft-xls",
|
||||
"craft-xml",
|
||||
"gridcraft-core",
|
||||
"gridcraft-formula",
|
||||
"gridcraft-functions",
|
||||
|
||||
@@ -32,6 +32,7 @@ gridcraft-math = { path = "crates/math" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "=0.1.0", features = ["egui"] }
|
||||
# PDF RunLength encoding; this revision also fixes the vendored JBIG2 dependency for Git consumers.
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "bc358686389892a3827e64fc26bedc278ef1e299", version = "0.1.0", default-features = false }
|
||||
craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f7e0d7fd5577e102b4634bcbe062e649eb68165f", version = "0.1.0" }
|
||||
# Compound files ([MS-CFB]) and password-encrypted OOXML packages ([MS-OFFCRYPTO]).
|
||||
craft-cfb = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||
@@ -41,7 +42,10 @@ craft-opc = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0
|
||||
# Delimited text (CSV, TSV) and SYLK; `crates/xlsx/src/csv.rs` and `crates/engine/src/io/sylk.rs`
|
||||
# turn them into workbooks.
|
||||
craft-csv = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||
# The native JSON workbook (`.json`, `.scjson`): read, written, and kept newer macros written back.
|
||||
craft-gridcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "9a6d894200221fcfedc274870c30394d404f859d", version = "0.1.0" }
|
||||
# Excel 97-2003 (.xls, BIFF8) workbooks; `crates/xlsx/src/xls.rs` maps them onto the model.
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||
craft-xls = { git = "https://github.com/storytold/craft-libs", rev = "bb57d422d0bc842cbde430955825553ab7b976f4", version = "0.1.0" }
|
||||
|
||||
# foundation
|
||||
|
||||
@@ -205,7 +205,7 @@ egui frontend is a separate crate, so the UI can be swapped without touching the
|
||||
|
||||
GridCraft is in **alpha**: the core workflow works end to end, but depth, fidelity and file
|
||||
compatibility are still rough. It covers 89% of standard ribbon commands in our catalog
|
||||
([`docs/parity-checklist.md`](docs/parity-checklist.md)) and 513 standard worksheet functions
|
||||
([`docs/parity-checklist.md`](docs/parity-checklist.md)) and 514 standard worksheet functions
|
||||
([`docs/function-parity.md`](docs/function-parity.md)); this is a parity inventory, not a count of working implementations. Weighted by what spreadsheet users rely on, we
|
||||
estimate it is about 50% ready for real work. Next up: XLSX fidelity on real-world files, very large
|
||||
workbooks and multi-threaded recalc, chart depth, text in every script, and `.xls` import. Stage,
|
||||
|
||||
+5
-2
@@ -2,6 +2,7 @@
|
||||
|
||||
**Stage: alpha** · next: beta, ~25 points of "ready for real work" and ~160–240 h away
|
||||
|
||||
> **Last reviewed:** 2026-11-15 · **Last updated:** 2026-11-15 · **Change:** minor (performance: formula entry and XLSX save win back time lost since 23829d8c (#2654), 465 → 420 ms and 540 → 488 ms on the 100k-row benchmark; Sandbox refuses fcntl's asynchronous notification and the socket ioctls that notify another process on Linux (#3846); CI provisions pinned fonts for coverage tests; the oversized pivot-cache warning's test names the part limit; readiness estimates unchanged) · **Target:** Microsoft Excel (Microsoft 365)
|
||||
> **Last reviewed:** 2026-11-01 · **Last updated:** 2026-11-05 · **Change:** minor (CJK fallback text shares the Latin baseline; earlier: form controls: buttons, sliders and spin buttons; earlier: RefEdit reference boxes in dialogs: Goal Seek, Solver and Data Analysis take ranges by selection on the grid; earlier: Python mode in the formula bar; earlier: Python cells stored and kept in files; earlier: equations: Insert › Equation, editor, gridcraft-math; earlier: What-if and analysis: Solver Sensitivity report for Simplex LP and GRG Nonlinear; earlier: floating objects: one selection, eight resize handles, keyboard delete; earlier: Chart data tables: live source values beneath column, bar, line, area and compatible combo charts; legend keys and borders; XLSX round-trip and print/PDF; earlier: Formulas › Function Library as labelled buttons with category menus; Recently Used and Insert Function categories; XLSX workbook-view selection, bounded tab ratios and sheet-edit regressions; readiness estimates unchanged; earlier: CSV and text open detects each column's date order, so day-first dates are not silently swapped) · **Target:** Microsoft Excel (Microsoft 365)
|
||||
|
||||
GridCraft aims at full Microsoft Excel parity, and at being better in places: faster, open (XLSX
|
||||
@@ -22,7 +23,7 @@ This page is the summary. The detail is in:
|
||||
| Number | Value | Kind |
|
||||
|---|---|---|
|
||||
| 2026-10-14 | Editing a cell with text that would read back as a number, boolean, date or formula (entered with a leading apostrophe) shows the apostrophe in the editor and formula bar, so Enter unchanged keeps it text (#1362) |
|
||||
| **Feature breadth** (weighted) | **~75%** | estimated, anchored on two measurements: ribbon catalog 281 / 296 (94.9%), worksheet functions 513 / 523 (98.1%; 504 working, 96.4%) |
|
||||
| **Feature breadth** (weighted) | **~75%** | estimated, anchored on two measurements: ribbon catalog 281 / 296 (94.9%), worksheet functions 514 / 523 (98.3%; 505 working, 96.6%) |
|
||||
| **Ready for real work** | **~50%** | estimated from written weights (51.6); [target-app-parity.md](docs/target-app-parity.md) |
|
||||
| **Mainstream practitioner** | **~50%** | estimated: typical analyst/finance user, weekly features, × 0.90 interaction × 0.92 stability × 0.88 file exchange; [method](docs/target-app-parity.md#mainstream-practitioner) |
|
||||
| **Essentials user** | **~63%** | estimated: core features only, × 0.92 launch/stability × 0.95 clarity × 0.90 opening sent files; [method](docs/target-app-parity.md#essentials-user) |
|
||||
@@ -74,7 +75,7 @@ collaboration, mobile, AI).
|
||||
| Area | Breadth | Ready | Hours | Doc |
|
||||
|---|---|---|---|---|
|
||||
| Formula language and calculation | ~92% | ~72% | 20–30 | [target-app-parity.md](docs/target-app-parity.md#feature-areas) |
|
||||
| Worksheet functions | 96.6% measured | ~82% | 16–26 | [function-parity.md](docs/function-parity.md) |
|
||||
| Worksheet functions | 96.6% measured | ~82% | 15–25 | [function-parity.md](docs/function-parity.md) |
|
||||
| Editing, navigation, clipboard, fill | ~90% | ~70% | 15–25 | [ui-parity.md](docs/ui-parity.md) |
|
||||
| Cell formatting, styles, conditional formatting | ~95% | ~80% | 8–14 | [target-app-parity.md](docs/target-app-parity.md#feature-areas) |
|
||||
| Sort, filter, tables, validation, outline | ~82% | ~70% | 10–16 | [target-app-parity.md](docs/target-app-parity.md#feature-areas) |
|
||||
@@ -202,6 +203,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in
|
||||
| 2026-10-13 | Conditional formatting: a rule gathers range statistics only when it reads them (top/bottom, above average, duplicates, scales, bars, icons) and borrows them instead of copying them per cell, so the per-frame lookup of an expression or cell-value rule no longer visits its whole range (#1098, part 1) |
|
||||
| 2026-10-13 | Grid: resizing several selected columns or rows previews on the dragged one and applies the size to all on release; Esc cancels (#1082) |
|
||||
| 2026-10-12 | Next/previous sheet navigation stops at the first/last visible worksheet instead of activating a hidden boundary sheet; the current selection is retained |
|
||||
| 2026-10-12 | GETPIVOTDATA reads PivotTable values by field and items (#284) |
|
||||
| 2026-10-12 | PDF writer: objects are written straight to the output, identical pictures are stored once, style operators are emitted only when they change, `q` nesting is limited to 28 and polyline joins no longer leak into later strokes (#816) |
|
||||
| 2026-10-12 | Insert › Text › WordArt (`insert.wordArt`, `wordArt.set`): floating decorative text with 10 original styles, outline and shadow, in-place editing, XLSX and print (#784) |
|
||||
| 2026-10-12 | Number formatting: one table of built-in formats (xlsx); numbers, dates and General render with one scratch buffer instead of per-token strings; output unchanged, checked against digests recorded from the old code (#817) |
|
||||
@@ -321,6 +323,7 @@ Ranked; estimates in Opus 5.5 agent-hours. Detail and the full beta-gate list in
|
||||
| 2026-10-13 | trivial | Progress log: shared pictures written once on XLSX export (#985) |
|
||||
| 2026-10-13 | minor | Progress log: conditional-format lookups no longer scan the range for rules without statistics (#1098) |
|
||||
| 2026-10-12 | minor | Progress log: hidden-sheet navigation at workbook boundaries |
|
||||
| 2026-10-12 | minor | Worksheet functions 514 / 523 (GETPIVOTDATA); progress log row |
|
||||
| 2026-10-13 | trivial | Progress log: charts cached between frames (#1139) |
|
||||
| 2026-10-12 | minor | Progress log: PDF writer cleanup (#816) |
|
||||
| 2026-10-12 | minor | Catalog 276 → 277 / 292: Insert › WordArt (#784) |
|
||||
|
||||
@@ -368,6 +368,8 @@ pub fn check_bytes(path: &str, bytes: &[u8], opts: &Options) -> FileReport {
|
||||
}
|
||||
|
||||
fn check_inner(path: &str, bytes: &[u8], opts: &Options) -> FileReport {
|
||||
// GETPIVOTDATA needs the engine's pivot indexer; without it every such cell reads #REF!.
|
||||
let _ = gridcraft_engine::model::PIVOT_INDEXER.set(gridcraft_engine::pivot::index_cells);
|
||||
let mut report = FileReport { path: path.to_string(), ..Default::default() };
|
||||
let (cached, warnings) = match gridcraft_engine::io::open_bytes(path, bytes) {
|
||||
Ok(x) => x,
|
||||
|
||||
@@ -72,6 +72,7 @@ impl<'h> Evaluator<'h> {
|
||||
"XLOOKUP" => self.xlookup(args),
|
||||
"CELL" => self.cell_info(args),
|
||||
"TRIMRANGE" => self.trimrange(args),
|
||||
"GETPIVOTDATA" => self.getpivotdata(args),
|
||||
"SUBTOTAL" | "AGGREGATE" => self.subtotal(name, args),
|
||||
"TEXT" => {
|
||||
if args.len() != 2 {
|
||||
|
||||
@@ -136,6 +136,25 @@ impl Precedents<'_> {
|
||||
(_, Some(Expr::Number(_) | Expr::Text(_) | Expr::Bool(_) | Expr::Error(_) | Expr::Array(_) | Expr::Missing)) => {}
|
||||
_ => self.dynamic = true,
|
||||
},
|
||||
// GETPIVOTDATA reads the report cells, so it depends on the whole report its reference
|
||||
// points into (pivot commands recalculate everything). Any other reference is dynamic.
|
||||
Expr::Call(n, args) if n == "GETPIVOTDATA" => match args.get(1) {
|
||||
Some(Expr::Ref(r)) => {
|
||||
let si = match &r.sheet {
|
||||
SheetSel::Current => Some(self.sheet),
|
||||
SheetSel::Named(name) => self.wb.sheet_index(name),
|
||||
SheetSel::Span(..) => None,
|
||||
};
|
||||
let report = si
|
||||
.and_then(|i| self.wb.sheet(i))
|
||||
.and_then(|sh| sh.pivots.iter().find_map(|p| p.last_range.filter(|lr| lr.intersects(&r.range()))));
|
||||
match report {
|
||||
Some(lr) => self.push(r, lr, boxes),
|
||||
None => self.dynamic = true,
|
||||
}
|
||||
}
|
||||
_ => self.dynamic = true,
|
||||
},
|
||||
Expr::Call(n, _)
|
||||
if matches!(n.as_str(), "INDIRECT" | "OFFSET" | "NOW" | "TODAY" | "RAND" | "RANDBETWEEN" | "RANDARRAY" | "CELL" | "INFO") =>
|
||||
{
|
||||
@@ -199,6 +218,7 @@ fn is_special(n: &str) -> bool {
|
||||
| "INDEX"
|
||||
| "CELL"
|
||||
| "TRIMRANGE"
|
||||
| "GETPIVOTDATA"
|
||||
| "SUBTOTAL"
|
||||
| "AGGREGATE"
|
||||
| "TEXT"
|
||||
@@ -237,6 +257,7 @@ pub const SPECIAL_FUNCTIONS: &[&str] = &[
|
||||
"INDEX",
|
||||
"CELL",
|
||||
"TRIMRANGE",
|
||||
"GETPIVOTDATA",
|
||||
"SUBTOTAL",
|
||||
"AGGREGATE",
|
||||
"TEXT",
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
pub mod eval;
|
||||
mod pivotdata;
|
||||
mod precision;
|
||||
pub mod recalc;
|
||||
mod spill_index;
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
//! GETPIVOTDATA: a value from a PivotTable report, found by its value field and the row and
|
||||
//! column items that locate it (Excel's documented semantics). Each PivotTable's value cells are
|
||||
//! indexed in `PivotTable::data_index` (set on refresh and saved with the report; built on first
|
||||
//! use only for a pivot loaded without one, and only when it matches the stored report); the
|
||||
//! result is read from the report cell the sheet shows.
|
||||
|
||||
use gridcraft_core::{CellError, CellRef, Value};
|
||||
use gridcraft_formula::Expr;
|
||||
use gridcraft_model::{PIVOT_INDEXER, PivotDataCell, PivotItemRef, PivotLookup, PivotTable};
|
||||
|
||||
use crate::eval::{Ev, Evaluator};
|
||||
|
||||
/// Excel allows 126 field/item pairs.
|
||||
const MAX_PAIRS: usize = 126;
|
||||
|
||||
fn same_text(a: &str, b: &str) -> bool {
|
||||
a.trim().to_lowercase() == b.trim().to_lowercase()
|
||||
}
|
||||
|
||||
/// A number matches an item with that value (dates as serials) or with that label; anything
|
||||
/// else matches the label as text. With `exact`, a number matches only an item of that value.
|
||||
fn item_matches(item: &PivotItemRef, v: &Value, exact: bool) -> bool {
|
||||
if let Value::Number(n) = v {
|
||||
if let Value::Number(x) = &item.value
|
||||
&& n == x
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if exact {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Value::Bool(b) = v {
|
||||
return item.value == Value::Bool(*b);
|
||||
}
|
||||
v.to_text().is_ok_and(|t| same_text(&t, &item.label))
|
||||
}
|
||||
|
||||
/// Whether `cell` is the value field asked for with exactly these items.
|
||||
fn cell_matches(cell: &PivotDataCell, data_field: &str, pairs: &[(String, Value)], exact: bool) -> bool {
|
||||
(same_text(&cell.data_field, data_field) || same_text(&cell.source_col, data_field))
|
||||
&& cell.items.len() == pairs.len()
|
||||
&& pairs.iter().all(|(f, v)| cell.items.iter().any(|it| same_text(&it.field, f) && item_matches(it, v, exact)))
|
||||
}
|
||||
|
||||
fn is_axis_field(pt: &PivotTable, field: &str) -> bool {
|
||||
pt.rows.iter().chain(pt.columns.iter()).any(|f| same_text(&f.source_col, field))
|
||||
}
|
||||
|
||||
/// The value cell whose value field and items are exactly those asked for. Text items hit the
|
||||
/// hash index; numbers and booleans also match by value, which a miss falls back to scanning for.
|
||||
/// A number prefers the item of that value: two numeric items can show the same label (0.6 and 1
|
||||
/// formatted as `0`), so a label hit counts only when no item has the exact value.
|
||||
fn find<'a>(cells: &'a PivotLookup, data_field: &str, pairs: &[(String, Value)]) -> Option<&'a PivotDataCell> {
|
||||
let labels: Option<Vec<(&str, String, bool)>> =
|
||||
pairs.iter().map(|(f, v)| v.to_text().ok().map(|t| (f.as_str(), t, matches!(v, Value::Bool(_))))).collect();
|
||||
let hit = labels.as_ref().and_then(|labels| {
|
||||
let refs: Vec<(&str, &str, bool)> = labels.iter().map(|(f, t, b)| (*f, t.as_str(), *b)).collect();
|
||||
cells.find(data_field, &refs)
|
||||
});
|
||||
if pairs.iter().all(|(_, v)| matches!(v, Value::Text(_))) {
|
||||
return hit;
|
||||
}
|
||||
if let Some(c) = hit.filter(|c| cell_matches(c, data_field, pairs, true)) {
|
||||
return Some(c);
|
||||
}
|
||||
let all = cells.cells()?;
|
||||
all.iter()
|
||||
.find(|cell| cell_matches(cell, data_field, pairs, true))
|
||||
.or(hit)
|
||||
.or_else(|| all.iter().find(|cell| cell_matches(cell, data_field, pairs, false)))
|
||||
}
|
||||
|
||||
impl Evaluator<'_> {
|
||||
pub(crate) fn getpivotdata(&mut self, args: &[Expr]) -> Ev {
|
||||
match self.pivot_value(args) {
|
||||
Ok(v) => Ev::V(v),
|
||||
Err(e) => Ev::V(Value::Error(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn scalar_arg(&mut self, e: &Expr) -> Result<Value, CellError> {
|
||||
match self.value(e).scalar() {
|
||||
Value::Error(e) => Err(e),
|
||||
v => Ok(v),
|
||||
}
|
||||
}
|
||||
|
||||
fn pivot_value(&mut self, args: &[Expr]) -> Result<Value, CellError> {
|
||||
let (Some(field_expr), Some(table_expr)) = (args.first(), args.get(1)) else { return Err(CellError::Value) };
|
||||
let rest = args.get(2..).unwrap_or_default();
|
||||
if rest.len() % 2 != 0 || rest.len() / 2 > MAX_PAIRS {
|
||||
return Err(CellError::Ref);
|
||||
}
|
||||
let data_field = self.scalar_arg(field_expr)?.to_text()?;
|
||||
let area = match self.eval(table_expr) {
|
||||
Ev::R(areas) => areas.first().copied().ok_or(CellError::Ref)?,
|
||||
Ev::V(Value::Error(e)) => return Err(e),
|
||||
_ => return Err(CellError::Ref),
|
||||
};
|
||||
let mut pairs: Vec<(String, Value)> = Vec::with_capacity(rest.len() / 2);
|
||||
for pair in rest.chunks(2) {
|
||||
let (Some(f), Some(i)) = (pair.first(), pair.get(1)) else { return Err(CellError::Ref) };
|
||||
let field = self.scalar_arg(f)?.to_text()?;
|
||||
let item = self.scalar_arg(i)?;
|
||||
if pairs.iter().any(|(g, _)| same_text(g, &field)) {
|
||||
return Err(CellError::Ref);
|
||||
}
|
||||
pairs.push((field, item));
|
||||
}
|
||||
let wb = self.host.workbook();
|
||||
let sheet = wb.sheet(area.sheet).ok_or(CellError::Ref)?;
|
||||
let pt = sheet.pivots.iter().find(|p| p.last_range.is_some_and(|r| r.intersects(&area.range))).ok_or(CellError::Ref)?;
|
||||
// A report filter field may be named when the report shows exactly that one item.
|
||||
let mut axis_pairs = Vec::with_capacity(pairs.len());
|
||||
for (field, item) in pairs {
|
||||
if is_axis_field(pt, &field) {
|
||||
axis_pairs.push((field, item));
|
||||
continue;
|
||||
}
|
||||
let filter = pt.filters.iter().find(|f| same_text(&f.source_col, &field)).ok_or(CellError::Ref)?;
|
||||
let shown = match filter.selected.as_deref() {
|
||||
Some([one]) => item.to_text().is_ok_and(|t| same_text(&t, one)),
|
||||
_ => false,
|
||||
};
|
||||
if !shown {
|
||||
return Err(CellError::Ref);
|
||||
}
|
||||
}
|
||||
// The report's value cells. A pivot loaded without them builds them once; a stored report
|
||||
// that no longer matches its source gets no index at all, so the lookup is #REF! until a
|
||||
// refresh — never an index cached from a failed build, because the shared lookup keeps
|
||||
// the first one set and undo or reopen could then never rebuild it.
|
||||
if pt.data_index.cells().is_none() {
|
||||
let build = PIVOT_INDEXER.get().ok_or(CellError::Ref)?;
|
||||
if let Ok(cells) = build(wb, area.sheet, pt) {
|
||||
pt.data_index.set_cells(cells);
|
||||
}
|
||||
}
|
||||
let cell = find(&pt.data_index, &data_field, &axis_pairs).ok_or(CellError::Ref)?;
|
||||
// The value is the one the sheet shows, so the formula and the report cell always agree.
|
||||
let report = pt.last_range.ok_or(CellError::Ref)?;
|
||||
let at = CellRef::new(report.start.row.saturating_add(cell.row), report.start.col.saturating_add(cell.col));
|
||||
if !report.contains(at) {
|
||||
return Err(CellError::Ref);
|
||||
}
|
||||
Ok(sheet.value(at))
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ thiserror = { workspace = true }
|
||||
log = { workspace = true }
|
||||
gridcraft-xlsx = { workspace = true }
|
||||
craft-csv = { workspace = true }
|
||||
craft-gridcraft-format = { workspace = true }
|
||||
gridcraft-chart = { workspace = true }
|
||||
gridcraft-pdf = { workspace = true }
|
||||
gridcraft-math = { workspace = true }
|
||||
|
||||
@@ -283,5 +283,8 @@ pub(super) fn subtotal(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let range = RangeRef::new(CellRef::new(first, *c), CellRef::new(last - 1, *c)).a1();
|
||||
s.execute("cell.set", json!({"sheet": sheet, "cell": CellRef::new(last, *c).a1(), "input": format!("=SUBTOTAL({code},{range})")}))?;
|
||||
}
|
||||
// One outer group over every data and subtotal row, summarised by the grand total, as in
|
||||
// Excel: outline level 1 then shows only the grand total, and level 2 the subtotals.
|
||||
s.execute("data.group", json!({"sheet": sheet, "rows": format!("{}:{}", first + 1, last)}))?;
|
||||
Ok(json!({"groups": inserted}))
|
||||
}
|
||||
|
||||
@@ -119,15 +119,29 @@ fn do_sort(s: &mut Session, sheet: usize, r: RangeRef, header: bool, keys: Vec<S
|
||||
for (ki, k) in keys.iter().enumerate() {
|
||||
let (va, ca) = &keyed[a as usize][ki];
|
||||
let (vb, cb) = &keyed[b as usize][ki];
|
||||
let plain = || {
|
||||
if case && va.is_text() && vb.is_text() {
|
||||
sort_compare(va, vb).then_with(|| case_order(va.as_text().unwrap_or(""), vb.as_text().unwrap_or("")))
|
||||
} else {
|
||||
sort_compare(va, vb)
|
||||
}
|
||||
};
|
||||
let o = if k.by != "values" {
|
||||
ca.cmp(cb)
|
||||
} else if let Some(list) = &k.list {
|
||||
let pos = |v: &Value| v.as_text().and_then(|t| list.iter().position(|x| x.eq_ignore_ascii_case(t))).unwrap_or(usize::MAX);
|
||||
pos(va).cmp(&pos(vb))
|
||||
} else if case && va.is_text() && vb.is_text() {
|
||||
sort_compare(va, vb).then_with(|| case_order(va.as_text().unwrap_or(""), vb.as_text().unwrap_or("")))
|
||||
let pos = |v: &Value| v.as_text().and_then(|t| list.iter().position(|x| x.eq_ignore_ascii_case(t)));
|
||||
match (pos(va), pos(vb)) {
|
||||
(Some(a), Some(b)) => a.cmp(&b),
|
||||
(Some(_), None) => Ordering::Less,
|
||||
(None, Some(_)) => Ordering::Greater,
|
||||
// Values not in the list follow the listed ones in the usual order, as in Excel.
|
||||
// A descending key is left as it was: they tie, so the next key decides.
|
||||
// A blank has no place in the list either, but still goes last.
|
||||
(None, None) if k.desc => va.is_empty().cmp(&vb.is_empty()),
|
||||
(None, None) => plain(),
|
||||
}
|
||||
} else {
|
||||
sort_compare(va, vb)
|
||||
plain()
|
||||
};
|
||||
// Blanks always sort last, whatever the order.
|
||||
let o = if k.desc && !(va.is_empty() || vb.is_empty()) { o.reverse() } else { o };
|
||||
|
||||
@@ -40,8 +40,8 @@ fn subtotal_puts_summary_rows_below_their_detail() {
|
||||
s.execute("data.subtotal", json!({"range": "A1:B4", "groupBy": "A", "columns": ["B"]})).unwrap();
|
||||
let sh = s.doc().unwrap().wb.active().unwrap().clone();
|
||||
assert!(sh.summary_below, "the totals sit below their groups");
|
||||
// East's detail is rows 2–3 and its total row 4: collapsing level 1 keeps the total showing.
|
||||
s.execute("data.showLevels", json!({"rows": 1})).unwrap();
|
||||
// East's detail is rows 2–3 and its total row 4: showing level 2 keeps the total showing.
|
||||
s.execute("data.showLevels", json!({"rows": 2})).unwrap();
|
||||
let hidden = |s: &Session, row: u32| s.doc().unwrap().wb.active().unwrap().is_row_hidden(row);
|
||||
assert!(hidden(&s, 1) && hidden(&s, 2), "East's detail rows are hidden");
|
||||
assert!(!hidden(&s, 3), "East Total stays visible");
|
||||
|
||||
@@ -36,15 +36,28 @@ pub(super) fn paste_special(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let whole = clip.areas.is_empty() && (clip.selected.is_full_cols() || clip.selected.is_full_rows()) && clip.selected.contains_range(&clip.range);
|
||||
let src = if whole { clip.selected } else { clip.range };
|
||||
let (h, w) = if transpose { (src.width(), src.height()) } else { (src.height(), src.width()) };
|
||||
// Tile the copy over a larger destination that is a multiple of its size.
|
||||
let tile = sel.height() % h == 0
|
||||
&& sel.width() % w == 0
|
||||
// Tile the copy over a larger destination that is a multiple of its size. A selection
|
||||
// narrower than the copy but a multiple of its height takes it down every row, at the copy's
|
||||
// width (and a shorter one a multiple of its width across), as in Excel.
|
||||
let multiple = sel.height() % h == 0 && sel.width() % w == 0;
|
||||
let down = sel.width() < w && sel.height() > h && sel.height() % h == 0;
|
||||
let across = sel.height() < h && sel.width() > w && sel.width() % w == 0;
|
||||
// The cells the tiles cover: the selection itself, or for `down`/`across` the selection at the
|
||||
// copy's width/height, which can be much larger than what was selected.
|
||||
let area = if down {
|
||||
u64::from(sel.height()) * u64::from(w)
|
||||
} else if across {
|
||||
u64::from(h) * u64::from(sel.width())
|
||||
} else {
|
||||
sel.count()
|
||||
};
|
||||
let tile = (multiple || down || across)
|
||||
&& !sel.is_single()
|
||||
&& cell_param_on(s, p, "at", dest_sheet)?.is_none()
|
||||
&& !sel.is_full_cols()
|
||||
&& !sel.is_full_rows()
|
||||
&& sel.count() <= 4_000_000;
|
||||
let (tiles_r, tiles_c) = if tile { (sel.height() / h, sel.width() / w) } else { (1, 1) };
|
||||
&& area <= 4_000_000;
|
||||
let (tiles_r, tiles_c) = if tile { ((sel.height() / h).max(1), (sel.width() / w).max(1)) } else { (1, 1) };
|
||||
// A single cell or row repeated down a filtered selection skips the rows the filter hides; a
|
||||
// taller block is pasted straight down, hidden rows included, as in Excel.
|
||||
let skip_rows = match s.doc()?.wb.sheet(dest_sheet) {
|
||||
|
||||
@@ -290,6 +290,12 @@ pub fn function_list() -> Vec<Json> {
|
||||
("SHEETS", "Information", "SHEETS([reference])", "Number of sheets."),
|
||||
("AREAS", "Lookup", "AREAS(reference)", "Number of areas in a reference."),
|
||||
("TRIMRANGE", "Lookup", "TRIMRANGE(range, [trim_rows], [trim_cols])", "A range or array without its blank outer rows and columns."),
|
||||
(
|
||||
"GETPIVOTDATA",
|
||||
"Lookup",
|
||||
"GETPIVOTDATA(data_field, pivot_table, [field1, item1], ...)",
|
||||
"A value from a PivotTable report, by value field and items.",
|
||||
),
|
||||
("ISOMITTED", "Information", "ISOMITTED(argument)", "TRUE when a LAMBDA argument was left out."),
|
||||
];
|
||||
for (n, c, sig, d) in specials {
|
||||
|
||||
+21
-1586
File diff suppressed because it is too large
Load Diff
@@ -1,17 +1,38 @@
|
||||
use super::{
|
||||
Anchor, CellRef, Chart, ChartKind, EngineError, Json, LegendPos, RangeRef, Result, Series, Session, Sheet, anchor_mode_param, bad, block,
|
||||
bool_param, cell_param_on, edit, f64_param, json, split_sheet, str_param, target_ranges, target_sheet, u32_param,
|
||||
Anchor, CellRef, Chart, ChartKind, EngineError, Json, LegendPos, MAX_COLS, MAX_ROWS, RangeRef, Result, Series, Session, Sheet, anchor_mode_param,
|
||||
bad, block, bool_param, cell_param_on, edit, f64_param, json, size_cap, split_sheet, str_param, target_ranges, target_sheet, u32_param,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn compiled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn chart_areas(s: &Session, p: &Json) -> Result<Vec<RangeRef>> {
|
||||
if p.get("range").is_some() {
|
||||
return target_ranges(s, p);
|
||||
let mut areas = if p.get("range").is_some() {
|
||||
target_ranges(s, p)?
|
||||
} else if s.doc()?.selection.ranges.len() > 1 {
|
||||
s.doc()?.selection.ranges.clone()
|
||||
} else {
|
||||
vec![block(s, p)?]
|
||||
};
|
||||
// Whole columns/rows span a million cells: clip their far edges to the cells in use, so only
|
||||
// a block that really is too large gets refused. Bounded areas keep their extent as given.
|
||||
let sheet = target_sheet(s, p)?;
|
||||
if let Some(used) = s.doc()?.wb.sheet(sheet).and_then(|sh| sh.used_range()) {
|
||||
// Areas that start outside the used range keep their extent as given.
|
||||
for r in &mut areas {
|
||||
let whole_cols = r.start.row == 0 && r.end.row >= MAX_ROWS - 1;
|
||||
let whole_rows = r.start.col == 0 && r.end.col >= MAX_COLS - 1;
|
||||
if whole_cols && r.start.row <= used.end.row {
|
||||
r.end.row = r.end.row.min(used.end.row);
|
||||
}
|
||||
if whole_rows && r.start.col <= used.end.col {
|
||||
r.end.col = r.end.col.min(used.end.col);
|
||||
}
|
||||
}
|
||||
}
|
||||
let d = s.doc()?;
|
||||
if d.selection.ranges.len() > 1 {
|
||||
return Ok(d.selection.ranges.clone());
|
||||
}
|
||||
Ok(vec![block(s, p)?])
|
||||
Ok(areas)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- charts
|
||||
@@ -263,6 +284,8 @@ pub fn build_chart(s: &Session, p: &Json) -> Result<(usize, Chart)> {
|
||||
data_table: None,
|
||||
gridlines: !matches!(kind, ChartKind::Pie | ChartKind::Doughnut | ChartKind::Treemap | ChartKind::Sunburst | ChartKind::Funnel),
|
||||
style: 1,
|
||||
hole_size: 75,
|
||||
first_slice_angle: 0,
|
||||
x_title: None,
|
||||
y_title: None,
|
||||
source: (areas.len() == 1).then(|| format!("{}!{}", gridcraft_formula::quote_sheet(&sh.name), bounds.a1())),
|
||||
@@ -308,7 +331,11 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let Some(c) = sh.charts.get_mut(ci) else { return Ok(Json::Null) };
|
||||
if let Some(t) = str_param(p, "type") {
|
||||
c.kind = chart_kind(t, str_param(p, "subtype").unwrap_or(""));
|
||||
if !c.supports_data_table() {
|
||||
c.data_table = None;
|
||||
}
|
||||
}
|
||||
update_data_table(c, p, bool_param(p, "dataTable"))?;
|
||||
if let Some(method) = quartiles {
|
||||
for series in &mut c.series {
|
||||
series.quartiles = method;
|
||||
@@ -335,6 +362,12 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
if let Some(v) = u32_param(p, "style") {
|
||||
c.style = v.clamp(1, 16);
|
||||
}
|
||||
if let Some(v) = u32_param(p, "holeSize") {
|
||||
c.hole_size = v.clamp(10, 90) as u8;
|
||||
}
|
||||
if let Some(v) = u32_param(p, "firstSliceAngle") {
|
||||
c.first_slice_angle = (v % 360) as u16;
|
||||
}
|
||||
if let Some(t) = p.get("xTitle") {
|
||||
c.x_title = t.as_str().map(str::to_string);
|
||||
}
|
||||
@@ -345,10 +378,10 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
c.anchor.cell = at;
|
||||
}
|
||||
if let Some(w) = f64_param(p, "width") {
|
||||
c.anchor.width = w.clamp(20.0, 10000.0) as f32;
|
||||
c.anchor.width = w.clamp(20.0, size_cap(c.anchor.width)) as f32;
|
||||
}
|
||||
if let Some(h) = f64_param(p, "height") {
|
||||
c.anchor.height = h.clamp(20.0, 10000.0) as f32;
|
||||
c.anchor.height = h.clamp(20.0, size_cap(c.anchor.height)) as f32;
|
||||
}
|
||||
if let Some(v) = f64_param(p, "dx") {
|
||||
c.anchor.dx = v as f32;
|
||||
@@ -360,6 +393,32 @@ pub(super) fn chart_set(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Shared by Chart Properties and Add Chart Element; no separate UI state.
|
||||
pub(crate) fn update_data_table(c: &mut Chart, p: &Json, on: Option<bool>) -> Result<()> {
|
||||
if p.get("dataTable").is_some_and(|v| !v.is_boolean()) {
|
||||
return Err(bad("chart", "`dataTable` must be a boolean"));
|
||||
}
|
||||
if on == Some(false) {
|
||||
c.data_table = None;
|
||||
return Ok(());
|
||||
}
|
||||
let fields = ["dataTableKeys", "dataTableHorizontalBorder", "dataTableVerticalBorder", "dataTableOutline"];
|
||||
if on == Some(true) || fields.iter().any(|k| p.get(k).is_some()) {
|
||||
if !c.supports_data_table() {
|
||||
return Err(bad("chart", "data tables need a column, bar, line, area or compatible combo chart"));
|
||||
}
|
||||
let table = c.data_table.get_or_insert_with(Default::default);
|
||||
for (key, value) in
|
||||
fields.into_iter().zip([&mut table.show_keys, &mut table.horizontal_border, &mut table.vertical_border, &mut table.outline])
|
||||
{
|
||||
if let Some(v) = p.get(key) {
|
||||
*value = v.as_bool().ok_or_else(|| bad("chart", format!("`{key}` must be a boolean")))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn chart_switch(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let (si, ci) = find_chart(s, p)?;
|
||||
edit(s, |cx| {
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
use super::{
|
||||
Anchor, BorderLine, BorderStyle, Borders, CfOperator, CfRule, CfValueKind, Color, CondFormat, EngineError, Fill, Json, Result, Session, Shape,
|
||||
ShapeKind, Style, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, ok, str_param, target_ranges, target_sheet, u32_param,
|
||||
Anchor, BorderLine, BorderStyle, Borders, CellRef, CfOperator, CfRule, CfValueKind, Color, CondFormat, EngineError, Fill, Json, RangeRef, Result,
|
||||
Session, Shape, ShapeKind, Style, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, ok, str_param, target_ranges,
|
||||
target_sheet, u32_param,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn compiled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- conditional formatting
|
||||
|
||||
fn preset_style(name: &str) -> Style {
|
||||
@@ -271,7 +277,13 @@ pub(super) fn clear_cf(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
sh.cond_formats.clear();
|
||||
} else {
|
||||
for cf in sh.cond_formats.iter_mut() {
|
||||
let before = RangeRef::top_left(&cf.ranges);
|
||||
cf.ranges.retain(|r| !ranges.iter().any(|x| x.intersects(r)));
|
||||
// The relative formulas are written for the top-left cell: when it goes, they're
|
||||
// rewritten for the new one, so the areas left keep reading the same cells.
|
||||
if let (Some(from), Some(to)) = (before, RangeRef::top_left(&cf.ranges)) {
|
||||
rebase_cf_formulas(&mut cf.rule, from, to);
|
||||
}
|
||||
}
|
||||
sh.cond_formats.retain(|c| !c.ranges.is_empty());
|
||||
}
|
||||
@@ -279,6 +291,19 @@ pub(super) fn clear_cf(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Moves the relative references of a rule's per-cell formulas written for `from` to `to`.
|
||||
fn rebase_cf_formulas(rule: &mut CfRule, from: CellRef, to: CellRef) {
|
||||
let mv = |f: &str| crate::cmd::data::move_rule_formula(f, from, to);
|
||||
match rule {
|
||||
CfRule::CellIs { a, b, .. } => {
|
||||
*a = mv(a);
|
||||
*b = b.as_deref().map(mv);
|
||||
}
|
||||
CfRule::Expression { formula, .. } => *formula = mv(formula),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn manage_cf(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let sheet = target_sheet(s, p)?;
|
||||
if p.get("delete").is_none() && p.get("moveUp").is_none() && p.get("moveDown").is_none() {
|
||||
|
||||
@@ -3,6 +3,11 @@ use super::{
|
||||
split_sheet, str_param, target_ranges, target_sheet,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn compiled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- links & comments
|
||||
|
||||
pub(super) fn insert_link(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
@@ -27,8 +32,10 @@ pub(super) fn insert_link(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
st.font.underline = Underline::Single;
|
||||
});
|
||||
let sh = cx.sheet_mut(sheet)?;
|
||||
if let Some(t) = text.clone().or_else(|| sh.value(at).is_empty().then(|| target.clone())) {
|
||||
sh.set_cell(at, Cell { value: gridcraft_core::Value::text(t.as_str()), formula: None, style: link_style });
|
||||
if let Some(t) = text.clone().or_else(|| {
|
||||
(sh.spill_anchor(at).is_none() && sh.value(at).is_empty() && sh.cell(at).is_none_or(|cell| !cell.has_content())).then(|| target.clone())
|
||||
}) {
|
||||
sh.set_cell(at, Cell { value: gridcraft_core::Value::text(t.as_str()), formula: None, style: link_style, py: None });
|
||||
} else {
|
||||
sh.set_style(at, link_style);
|
||||
}
|
||||
@@ -38,9 +45,11 @@ pub(super) fn insert_link(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
})
|
||||
}
|
||||
|
||||
/// Follows a link: a reference selects it, an `http`/`https`/`mailto` address is handed to the
|
||||
/// host (`UiRequest::OpenUrl`); anything else is refused ([`crate::links::classify`]). Opens no
|
||||
/// dialog; the interactive click asks for confirmation first, in the UI.
|
||||
/// Follows a link: a reference selects it; anything else is refused ([`crate::links::classify`]).
|
||||
/// An `http`/`https`/`mailto` address is refused too unless the host set
|
||||
/// [`crate::links::LinkPolicy::Allow`]: every caller of a command may be a script or an agent, so
|
||||
/// the user opens such links by clicking and confirming, and the UI then calls
|
||||
/// [`Session::open_confirmed_link`] (#2181). Opens no dialog.
|
||||
pub(super) fn open_link(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let target = match str_param(p, "url").or_else(|| str_param(p, "target")) {
|
||||
Some(t) => t.to_string(),
|
||||
@@ -56,6 +65,9 @@ pub(super) fn open_link(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
match crate::links::classify(&target) {
|
||||
crate::links::LinkKind::Internal(r) => crate::cmd::edit::go_to(s, &json!({"reference": r.trim_start_matches('#')})),
|
||||
crate::links::LinkKind::External(u) => {
|
||||
if s.link_policy != crate::links::LinkPolicy::Allow {
|
||||
return Err(EngineError::Other(crate::links::NEEDS_CONFIRMATION.into()));
|
||||
}
|
||||
s.ui_requests.push(crate::UiRequest::OpenUrl(u.clone()));
|
||||
Ok(json!({"opened": u}))
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
use super::{
|
||||
Anchor, CellPicture, CellRef, Color, EngineError, Image, Json, PROTECTED, Result, Session, Shape, ShapeKind, Sparkline, SparklineKind,
|
||||
anchor_mode_name, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, locked_cell_error, ok, str_param, u32_param,
|
||||
Anchor, CellPicture, CellRef, Color, EngineError, Image, Json, MAX_OBJECT_OFFSET, ObjKind, ObjRef, PROTECTED, Result, Session, Shape, ShapeKind,
|
||||
Sparkline, SparklineKind, anchor_mode_name, anchor_mode_param, bad, bool_param, cell_param, edit, f64_param, json, locked_cell_error, ok,
|
||||
size_cap, str_param, u32_param,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn compiled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub(super) fn insert_sparkline(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let src = str_param(p, "range").ok_or_else(|| bad("insert.sparkline", "missing `range`"))?.to_string();
|
||||
let loc = cell_param(s, p, "location")?.ok_or_else(|| bad("insert.sparkline", "missing `location`"))?;
|
||||
@@ -63,6 +69,10 @@ pub(super) fn insert_picture(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
.unwrap_or_else(|| if data.starts_with(&[0x89, b'P', b'N', b'G']) { "image/png".into() } else { "image/jpeg".into() });
|
||||
let (w, h) = crate::io::image_size(&data).unwrap_or((320, 240));
|
||||
let d = s.doc()?;
|
||||
// Sheet protection locks drawing objects, as for a text box's text.
|
||||
if d.wb.active().is_some_and(|sh| sh.is_protected()) {
|
||||
return Err(EngineError::Other(PROTECTED.into()));
|
||||
}
|
||||
let id = d.wb.next_object_id();
|
||||
let at = cell_param(s, p, "at")?.unwrap_or(d.selection.active);
|
||||
let scale = (640.0 / w.max(1) as f32).min(1.0);
|
||||
@@ -176,9 +186,15 @@ pub(super) fn shape_set_text(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let sheet = d.wb.active_sheet();
|
||||
let sh = d.wb.active().ok_or_else(|| bad("shape.setText", "no such text box"))?;
|
||||
let shape = sh.shapes.iter().find(|shape| shape.id == id).ok_or_else(|| bad("shape.setText", "no such text box"))?;
|
||||
if shape.kind != ShapeKind::TextBox {
|
||||
if !matches!(shape.kind, ShapeKind::TextBox | ShapeKind::WordArt) {
|
||||
return Err(bad("shape.setText", "the shape is not a text box"));
|
||||
}
|
||||
if shape.kind == ShapeKind::WordArt && text.is_empty() {
|
||||
return Err(bad("shape.setText", "WordArt text must not be empty"));
|
||||
}
|
||||
if shape.kind == ShapeKind::WordArt && text.chars().nth(crate::cmd::wordart::MAX_CHARS).is_some() {
|
||||
return Err(bad("shape.setText", format!("`text` is longer than {} characters", crate::cmd::wordart::MAX_CHARS)));
|
||||
}
|
||||
// Sheet protection locks drawing objects (there is no "edit objects" allowance yet).
|
||||
if sh.is_protected() {
|
||||
return Err(EngineError::Other(PROTECTED.into()));
|
||||
@@ -193,51 +209,50 @@ pub(super) fn shape_set_text(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The floating object a `{kind, id}` command names on the active sheet. Unknown kinds and
|
||||
/// objects are errors, so a stale id never succeeds silently.
|
||||
fn object_param(s: &Session, p: &Json, cmd: &str) -> Result<(usize, ObjRef)> {
|
||||
let id = u32_param(p, "id").ok_or_else(|| bad(cmd, "missing `id`"))?;
|
||||
let kind =
|
||||
str_param(p, "kind").and_then(ObjKind::parse).ok_or_else(|| bad(cmd, "kind must be chart, image, shape, slicer, equation or control"))?;
|
||||
let d = s.doc()?;
|
||||
let sheet = d.wb.active_sheet();
|
||||
let o = ObjRef::new(kind, id);
|
||||
if !d.wb.sheet(sheet).is_some_and(|sh| sh.has_object(o)) {
|
||||
return Err(bad(cmd, "no such object"));
|
||||
}
|
||||
// A locked form control on a protected sheet stays as it is.
|
||||
crate::cmd::controls::check_objects_unlocked(s, sheet, kind, &[id])?;
|
||||
Ok((sheet, o))
|
||||
}
|
||||
|
||||
pub(super) fn delete_object(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let id = u32_param(p, "id").ok_or_else(|| bad("object.delete", "missing `id`"))?;
|
||||
let kind = str_param(p, "kind").unwrap_or("").to_string();
|
||||
let sheet = s.doc()?.wb.active_sheet();
|
||||
let (sheet, o) = object_param(s, p, "object.delete")?;
|
||||
edit(s, |cx| {
|
||||
let sh = cx.sheet_mut(sheet)?;
|
||||
match kind.as_str() {
|
||||
"chart" => sh.charts.retain(|c| c.id != id),
|
||||
"image" => sh.images.retain(|c| c.id != id),
|
||||
"slicer" => sh.slicers.retain(|c| c.id != id),
|
||||
_ => sh.shapes.retain(|c| c.id != id),
|
||||
}
|
||||
Ok(Json::Null)
|
||||
cx.sheet_mut(sheet)?.remove_object(o);
|
||||
Ok(json!({"deleted": o}))
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn move_object(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let id = u32_param(p, "id").ok_or_else(|| bad("object.move", "missing `id`"))?;
|
||||
let kind = str_param(p, "kind").unwrap_or("").to_string();
|
||||
let sheet = s.doc()?.wb.active_sheet();
|
||||
let (sheet, o) = object_param(s, p, "object.move")?;
|
||||
let at = cell_param(s, p, "at")?;
|
||||
edit(s, |cx| {
|
||||
let sh = cx.sheet_mut(sheet)?;
|
||||
let anchor = match kind.as_str() {
|
||||
"chart" => sh.charts.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
"image" => sh.images.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
"slicer" => sh.slicers.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
"shape" => sh.shapes.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
_ => None,
|
||||
};
|
||||
let Some(a) = anchor else { return Err(bad("object.move", "no such object")) };
|
||||
let Some(a) = cx.sheet_mut(sheet)?.object_anchor_mut(o) else { return Err(bad("object.move", "no such object")) };
|
||||
if let Some(at) = at {
|
||||
a.cell = at;
|
||||
}
|
||||
if let Some(v) = f64_param(p, "dx") {
|
||||
a.dx = v as f32;
|
||||
a.dx = v.clamp(-MAX_OBJECT_OFFSET, MAX_OBJECT_OFFSET) as f32;
|
||||
}
|
||||
if let Some(v) = f64_param(p, "dy") {
|
||||
a.dy = v as f32;
|
||||
a.dy = v.clamp(-MAX_OBJECT_OFFSET, MAX_OBJECT_OFFSET) as f32;
|
||||
}
|
||||
if let Some(v) = f64_param(p, "width") {
|
||||
a.width = v.clamp(1.0, 10000.0) as f32;
|
||||
a.width = v.clamp(1.0, size_cap(a.width)) as f32;
|
||||
}
|
||||
if let Some(v) = f64_param(p, "height") {
|
||||
a.height = v.clamp(0.0, 10000.0) as f32;
|
||||
a.height = v.clamp(0.0, size_cap(a.height)) as f32;
|
||||
}
|
||||
Ok(Json::Null)
|
||||
})
|
||||
@@ -247,21 +262,10 @@ pub(super) fn move_object(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
/// cells" / "Don't move or size with cells"), so it follows — or ignores — its rows and columns
|
||||
/// when the sheet is sorted or edited structurally.
|
||||
pub(super) fn set_anchor_mode(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let id = u32_param(p, "id").ok_or_else(|| bad("object.setAnchorMode", "missing `id`"))?;
|
||||
let kind = str_param(p, "kind").unwrap_or("").to_string();
|
||||
if !matches!(kind.as_str(), "chart" | "image" | "shape") {
|
||||
return Err(bad("object.setAnchorMode", "kind must be chart, image or shape"));
|
||||
}
|
||||
let (sheet, o) = object_param(s, p, "object.setAnchorMode")?;
|
||||
let mode = anchor_mode_param(p).ok_or_else(|| bad("object.setAnchorMode", "mode must be moveAndSize, moveOnly or absolute"))?;
|
||||
let sheet = s.doc()?.wb.active_sheet();
|
||||
edit(s, |cx| {
|
||||
let sh = cx.sheet_mut(sheet)?;
|
||||
let anchor = match kind.as_str() {
|
||||
"chart" => sh.charts.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
"image" => sh.images.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
_ => sh.shapes.iter_mut().find(|c| c.id == id).map(|c| &mut c.anchor),
|
||||
};
|
||||
let Some(a) = anchor else { return Err(bad("object.setAnchorMode", "no such object")) };
|
||||
let Some(a) = cx.sheet_mut(sheet)?.object_anchor_mut(o) else { return Err(bad("object.setAnchorMode", "no such object")) };
|
||||
a.mode = mode;
|
||||
Ok(json!({"mode": anchor_mode_name(mode)}))
|
||||
})
|
||||
|
||||
@@ -3,6 +3,11 @@ use super::{
|
||||
block, bool_param, edit, json, rewrite, shift_cell_features, str_param, target_range, target_sheet, with,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
pub(super) fn compiled() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- tables
|
||||
|
||||
pub(super) fn insert_table(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
@@ -51,7 +56,7 @@ pub(super) fn insert_table(s: &mut Session, p: &Json) -> Result<Json> {
|
||||
let sh = cx.sheet_mut(sheet)?;
|
||||
// The header row pushes the data down one row: never off the end of the sheet.
|
||||
let last = RangeRef::new(CellRef::new(MAX_ROWS - 1, r.start.col), CellRef::new(MAX_ROWS - 1, r.end.col));
|
||||
if sh.cells.iter_range(last).any(|(_, x)| x.formula.is_some() || !x.value.is_empty()) {
|
||||
if sh.cells.iter_range(last).any(|(_, x)| x.has_content()) {
|
||||
return Err(EngineError::Other("To prevent possible loss of data, cells can't be pushed off the end of the worksheet.".into()));
|
||||
}
|
||||
sh.cells.shift_rows_in_cols(r.start.col, r.end.col, r.start.row, 1);
|
||||
@@ -211,7 +216,10 @@ fn write_totals(sh: &mut Sheet, ti: usize) {
|
||||
let c = CellRef::new(row, t.range.start.col + i as u32);
|
||||
if let Some(code) = col.totals.subtotal_code() {
|
||||
let f = format!("=SUBTOTAL({code},{}[{}])", t.name, col.name);
|
||||
sh.set_cell(c, Cell { formula: Some(std::sync::Arc::new(Formula::new(&f))), value: gridcraft_core::Value::Empty, style: sh.style_id(c) });
|
||||
sh.set_cell(
|
||||
c,
|
||||
Cell { formula: Some(std::sync::Arc::new(Formula::new(&f))), value: gridcraft_core::Value::Empty, style: sh.style_id(c), py: None },
|
||||
);
|
||||
} else if let Some(l) = &col.totals_label {
|
||||
sh.set_value(c, gridcraft_core::Value::text(l.as_str()));
|
||||
} else {
|
||||
|
||||
@@ -628,6 +628,312 @@ fn calculated_field_errors() {
|
||||
assert!(matches!(s.ui_requests.last(), Some(crate::UiRequest::Dialog(n, _)) if n == "pivotCalculatedField"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_reads_the_report() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "columns": ["Product"], "values": ["Sales"]})).unwrap();
|
||||
assert_eq!(pt(&s).last_range.unwrap().a1(), "A3:E8");
|
||||
let gp = |s: &mut Session, cell: &str, f: &str| {
|
||||
s.execute("cell.set", json!({"cell": cell, "input": f})).unwrap();
|
||||
val(s, cell)
|
||||
};
|
||||
// Item cell, row subtotal by any cell of the report, grand total; names and items ignore case.
|
||||
assert_eq!(gp(&mut s, "G1", r#"=GETPIVOTDATA("Sales",$A$3,"Region","East","Product","Apples")"#), Value::Number(160.0));
|
||||
assert_eq!(gp(&mut s, "G2", r#"=GETPIVOTDATA("sales",C6,"region","east")"#), Value::Number(415.0));
|
||||
assert_eq!(gp(&mut s, "G3", r#"=GETPIVOTDATA("Sum of Sales",A3)"#), Value::Number(TOTAL));
|
||||
assert_eq!(gp(&mut s, "G4", r#"=GETPIVOTDATA("Sales",A3,"Product","Pears")"#), Value::Number(270.0));
|
||||
// Not in the report: unknown item, value field, field, unpaired field, not a pivot cell.
|
||||
for (cell, f) in [
|
||||
("H1", r#"=GETPIVOTDATA("Sales",A3,"Region","South")"#),
|
||||
("H2", r#"=GETPIVOTDATA("Units",A3)"#),
|
||||
("H3", r#"=GETPIVOTDATA("Sales",A3,"Date","East")"#),
|
||||
("H4", r#"=GETPIVOTDATA("Sales",A3,"Region")"#),
|
||||
("H5", r#"=GETPIVOTDATA("Sales",Z99)"#),
|
||||
("H6", r#"=GETPIVOTDATA("Sales",A3,"Region","East","Region","East")"#),
|
||||
] {
|
||||
assert_eq!(gp(&mut s, cell, f), Value::Error(CellError::Ref), "{f}");
|
||||
}
|
||||
assert_eq!(gp(&mut s, "H7", r#"=GETPIVOTDATA("Sales",A3,"Region",NA())"#), Value::Error(CellError::NA));
|
||||
// A refresh after a source edit updates the result.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "E2", "input": "1100"})).unwrap();
|
||||
s.execute("data.refreshAll", json!({})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(val(&s, "G1"), Value::Number(1160.0));
|
||||
// Opening a saved workbook starts without an index (files don't carry it); the first
|
||||
// GETPIVOTDATA builds it.
|
||||
let wb = (*s.doc().unwrap().wb).clone();
|
||||
let (back, _) = gridcraft_xlsx::read_xlsx(&gridcraft_xlsx::write_xlsx(&wb).unwrap()).unwrap();
|
||||
s.add_document(crate::DocState::new(back, None, "Reopened".into(), crate::Trust::FromFile));
|
||||
let d = s.doc().unwrap();
|
||||
let sh = d.wb.sheet(d.wb.sheet_index("Sheet2").unwrap()).unwrap();
|
||||
assert!(sh.pivots.first().unwrap().data_index.cells().is_some());
|
||||
assert_eq!(sh.value(CellRef::parse("G1").unwrap()), Value::Number(1160.0));
|
||||
assert_eq!(sh.value(CellRef::parse("G3").unwrap()), Value::Number(TOTAL + 1000.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_reads_the_displayed_report() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
// The source changes after the last refresh, then the workbook is saved and reopened:
|
||||
// the report still shows the old numbers, and the formula agrees with the cell.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "E2", "input": "1100"})).unwrap();
|
||||
let wb = (*s.doc().unwrap().wb).clone();
|
||||
let (back, _) = gridcraft_xlsx::read_xlsx(&gridcraft_xlsx::write_xlsx(&wb).unwrap()).unwrap();
|
||||
s.add_document(crate::DocState::new(back, None, "Reopened".into(), crate::Trust::FromFile));
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
let r = pt(&s).last_range.unwrap();
|
||||
let at = r.start.a1();
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": format!(r#"=GETPIVOTDATA("Sales",{at},"Region","East")"#)})).unwrap();
|
||||
let d = s.doc().unwrap();
|
||||
let sh = d.wb.sheet(d.wb.sheet_index("Sheet2").unwrap()).unwrap();
|
||||
let east = (r.start.row..=r.end.row).find(|row| sh.value(CellRef::new(*row, r.start.col)) == Value::Text("East".into())).unwrap();
|
||||
let shown = sh.value(CellRef::new(east, r.start.col + 1));
|
||||
assert_eq!(shown, Value::Number(415.0));
|
||||
assert_eq!(val(&s, "K1"), shown);
|
||||
}
|
||||
|
||||
/// `=GETPIVOTDATA("Sales", <report>, "Region", <region>)` evaluated in K1 of the active sheet.
|
||||
fn region_sales(s: &mut Session, region: &str) -> Value {
|
||||
let at = pt(s).last_range.unwrap().start.a1();
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": format!(r#"=GETPIVOTDATA("Sales",{at},"Region","{region}")"#)})).unwrap();
|
||||
val(s, "K1")
|
||||
}
|
||||
|
||||
fn reopen(s: &mut Session) {
|
||||
let wb = (*s.doc().unwrap().wb).clone();
|
||||
let (back, _) = gridcraft_xlsx::read_xlsx(&gridcraft_xlsx::write_xlsx(&wb).unwrap()).unwrap();
|
||||
s.add_document(crate::DocState::new(back, None, "Reopened".into(), crate::Trust::FromFile));
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_retries_after_a_lazy_build_fails() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
// A pivot read from a file carries no index, so the first lookup builds one.
|
||||
reopen(&mut s);
|
||||
assert!(pt(&s).data_index.cells().is_none());
|
||||
// The source changes, so the stored report is stale and the build finds nothing to trust.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "Alpha"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Error(CellError::Ref));
|
||||
assert!(pt(&s).data_index.cells().is_none(), "the failed build caches nothing");
|
||||
// The lookup is shared, so caching a failure as an empty index would leave every state that
|
||||
// shares it #REF! for good. Restoring the source lets the lookup build the index.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "East"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
assert!(pt(&s).data_index.cells().is_some(), "the lookup rebuilt after the failure");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_saves_no_index_when_the_lazy_build_fails() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
// A pivot read from a file carries no index; a source change makes the stored report stale,
|
||||
// so the lazy build fails and the lookup is #REF!.
|
||||
reopen(&mut s);
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "Alpha"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Error(CellError::Ref));
|
||||
// Saving the pivot must save no index at all, not an empty one: restoring an empty index
|
||||
// would count as an index and lock the reopened pivot against the lazy rebuild.
|
||||
let json = serde_json::to_string(&pt(&s)).unwrap();
|
||||
let back: gridcraft_model::PivotTable = serde_json::from_str(&json).unwrap();
|
||||
assert!(json.contains(r#""data_index":null"#), "a failed build saves no index, not an empty one: {json}");
|
||||
assert!(back.data_index.cells().is_none());
|
||||
// Reopened with the source restored, the lookup builds the index.
|
||||
reopen(&mut s);
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "East"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_keeps_the_refreshed_report_when_an_item_is_inserted() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
// A new first item in the source shifts every item of a fresh report down one row.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "Alpha"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
// Before the refresh the report still shows the old items, and the lookup reads that report.
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
assert_eq!(region_sales(&mut s, "Alpha"), Value::Error(CellError::Ref));
|
||||
// Saved and reopened unrefreshed: the stored report no longer matches the source, so there
|
||||
// is no index to trust (never the shifted cell of a different item).
|
||||
reopen(&mut s);
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Error(CellError::Ref));
|
||||
assert_eq!(region_sales(&mut s, "Alpha"), Value::Error(CellError::Ref));
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("data.refreshAll", json!({})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "Alpha"), Value::Number(100.0));
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
assert_eq!(region_sales(&mut s, "East"), Value::Number(315.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_keeps_the_refreshed_report_when_an_item_is_removed() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "North"), Value::Number(135.0));
|
||||
// Every North row becomes East: North leaves the report and West moves up.
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
for a in ["A5", "A8", "A11"] {
|
||||
s.execute("cell.set", json!({"cell": a, "input": "East"})).unwrap();
|
||||
}
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "North"), Value::Number(135.0));
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
reopen(&mut s);
|
||||
assert_eq!(region_sales(&mut s, "North"), Value::Error(CellError::Ref));
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Error(CellError::Ref));
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("data.refreshAll", json!({})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
assert_eq!(region_sales(&mut s, "North"), Value::Error(CellError::Ref));
|
||||
assert_eq!(region_sales(&mut s, "West"), Value::Number(285.0));
|
||||
assert_eq!(region_sales(&mut s, "East"), Value::Number(550.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_index_is_saved_with_an_unrefreshed_pivot() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet1"})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "A2", "input": "Alpha"})).unwrap();
|
||||
s.execute("sheet.activate", json!({"sheet": "Sheet2"})).unwrap();
|
||||
// The pivot as saved by the native format: the index of the stored report comes back with
|
||||
// it even though the source has since changed.
|
||||
let back: gridcraft_model::PivotTable = serde_json::from_str(&serde_json::to_string(&pt(&s)).unwrap()).unwrap();
|
||||
let cells = back.data_index.cells().expect("index saved");
|
||||
assert_eq!(cells, pt(&s).data_index.cells().unwrap());
|
||||
let west = back.data_index.find("Sales", &[("Region", "West", false)]).unwrap();
|
||||
assert_eq!((west.row, west.col), (3, 1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_calculated_field() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Region"], "values": ["Sales"]})).unwrap();
|
||||
s.execute("pivot.calculatedField", json!({"name": "Double", "formula": "=Sales*2"})).unwrap();
|
||||
let at = pt(&s).last_range.unwrap().start.a1();
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": format!(r#"=GETPIVOTDATA("Double",{at},"Region","East")"#)})).unwrap();
|
||||
assert_eq!(val(&s, "K1"), Value::Number(830.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn getpivotdata_report_filter() {
|
||||
let mut s = sales();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Product"], "values": ["Sales"], "filters": ["Region"]})).unwrap();
|
||||
let at = pt(&s).last_range.unwrap().start.a1();
|
||||
let f = |region: &str| format!(r#"=GETPIVOTDATA("Sales",{at},"Region","{region}","Product","Apples")"#);
|
||||
// With every item shown, naming the filter field is #REF!.
|
||||
s.execute("cell.set", json!({"cell": "H1", "input": f("East")})).unwrap();
|
||||
assert_eq!(val(&s, "H1"), Value::Error(CellError::Ref));
|
||||
// Filtered to East: East matches, West doesn't.
|
||||
s.execute("pivot.filter", json!({"field": "Region", "selected": ["East"]})).unwrap();
|
||||
assert_eq!(val(&s, "H1"), Value::Number(160.0));
|
||||
s.execute("cell.set", json!({"cell": "H2", "input": f("West")})).unwrap();
|
||||
assert_eq!(val(&s, "H2"), Value::Error(CellError::Ref));
|
||||
}
|
||||
|
||||
/// A workbook whose Sheet1 holds `rows` under a two-column header, with a PivotTable of the first
|
||||
/// column (rows) and the second (sum) on a new sheet; the report sheet is active.
|
||||
fn two_column_pivot(header: [&str; 2], rows: Json, key_format: Option<&str>) -> Session {
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
let n = rows.as_array().map_or(0, Vec::len);
|
||||
let mut all = vec![json!(header)];
|
||||
all.extend(rows.as_array().cloned().unwrap_or_default());
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": all})).unwrap();
|
||||
if let Some(code) = key_format {
|
||||
s.execute("home.numberFormat", json!({"range": format!("A2:A{}", n + 1), "code": code})).unwrap();
|
||||
}
|
||||
s.execute("selection.set", json!({"range": "A1"})).unwrap();
|
||||
s.execute("insert.pivotTable", json!({"rows": [header[0]], "values": [header[1]]})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
/// The value the report shows for the row item `label` (one value field: the report's last column).
|
||||
fn shown(s: &Session, label: &str) -> Value {
|
||||
let r = pt(s).last_range.unwrap();
|
||||
let row = find_row(s, label).unwrap_or_else(|| panic!("{label} is not in the report"));
|
||||
val(s, &CellRef::new(row, r.end.col).a1())
|
||||
}
|
||||
|
||||
/// Inserting or deleting rows or columns inside a report keeps GETPIVOTDATA on the requested
|
||||
/// item's cell (the stored offsets move with the cells), and undo restores the old positions.
|
||||
#[test]
|
||||
fn getpivotdata_follows_rows_and_columns_edited_inside_the_report() {
|
||||
let mut s = two_column_pivot(["Region", "Sales"], json!([["East", 10], ["North", 30], ["West", 20]]), None);
|
||||
assert_eq!(pt(&s).last_range.unwrap().start.a1(), "A3");
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": r#"=GETPIVOTDATA("Sales",A3,"Region","West")"#})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "K2", "input": r#"=GETPIVOTDATA("Sales",A3,"Region","North")"#})).unwrap();
|
||||
assert_eq!(val(&s, "K1"), Value::Number(20.0));
|
||||
// Row 4 splits the header from the items; column B splits the labels from the values (and
|
||||
// moves the formulas from K to L).
|
||||
for (cmd, lines, west, north) in
|
||||
[("home.insertRows", json!({"rows": "4:4"}), "K1", "K2"), ("home.insertColumns", json!({"cols": "B:B"}), "L1", "L2")]
|
||||
{
|
||||
s.execute(cmd, lines).unwrap();
|
||||
assert_eq!(shown(&s, "West"), Value::Number(20.0), "{cmd}");
|
||||
assert_eq!(val(&s, west), shown(&s, "West"), "{cmd}");
|
||||
assert_eq!(val(&s, north), shown(&s, "North"), "{cmd}");
|
||||
}
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
s.execute("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(pt(&s).last_range.unwrap().start.a1(), "A3");
|
||||
s.execute("cell.set", json!({"cell": "K3", "input": r#"=GETPIVOTDATA("Sales",A3,"Region","West")"#})).unwrap();
|
||||
assert_eq!(val(&s, "K3"), Value::Number(20.0), "undo restores the report and its offsets");
|
||||
// Deleting North's row moves West up; North itself is gone from the report.
|
||||
let north = find_row(&s, "North").unwrap() + 1;
|
||||
s.execute("home.deleteRows", json!({"rows": format!("{north}:{north}")})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": r#"=GETPIVOTDATA("Sales",A3,"Region","West")"#})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "K2", "input": r#"=GETPIVOTDATA("Sales",A3,"Region","North")"#})).unwrap();
|
||||
assert_eq!(val(&s, "K1"), Value::Number(20.0));
|
||||
assert_eq!(val(&s, "K1"), shown(&s, "West"));
|
||||
assert_eq!(val(&s, "K2"), Value::Error(CellError::Ref), "a deleted value cell is not read from its old place");
|
||||
// Lines inserted at the report's first line move the whole report, and lines right after it
|
||||
// leave it alone; either way the offsets stay what they were.
|
||||
for rows in ["3:3", "9:9"] {
|
||||
s.execute("home.insertRows", json!({"rows": rows})).unwrap();
|
||||
let at = pt(&s).last_range.unwrap().start.a1();
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": format!(r#"=GETPIVOTDATA("Sales",{at},"Region","West")"#)})).unwrap();
|
||||
assert_eq!(val(&s, "K1"), Value::Number(20.0), "insert {rows}");
|
||||
assert_eq!(val(&s, "K1"), shown(&s, "West"), "insert {rows}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Numeric items whose formatted labels collide are told apart by value: an exact numeric item
|
||||
/// wins over another item that only displays the same label.
|
||||
#[test]
|
||||
fn getpivotdata_matches_numeric_items_by_value_before_label() {
|
||||
let mut s = two_column_pivot(["Key", "Sales"], json!([[0.6, 10], [1, 20]]), Some("0"));
|
||||
let p = pt(&s);
|
||||
let labels: Vec<&str> = p.data_index.cells().unwrap().iter().flat_map(|c| c.items.iter().map(|i| i.label.as_str())).collect();
|
||||
assert_eq!(labels, ["1", "1"], "both items display as 1");
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": r#"=GETPIVOTDATA("Sales",A3,"Key",1)"#})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "K2", "input": r#"=GETPIVOTDATA("Sales",A3,"Key",0.6)"#})).unwrap();
|
||||
assert_eq!(val(&s, "K1"), Value::Number(20.0));
|
||||
assert_eq!(val(&s, "K2"), Value::Number(10.0));
|
||||
// Dates: two times on one day show the same date label; each serial finds its own item.
|
||||
let mut s = two_column_pivot(["Day", "Sales"], json!([[45000, 10], [45000.25, 20]]), Some("m/d/yyyy"));
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": r#"=GETPIVOTDATA("Sales",A3,"Day",45000.25)"#})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "K2", "input": r#"=GETPIVOTDATA("Sales",A3,"Day",45000)"#})).unwrap();
|
||||
assert_eq!(val(&s, "K1"), Value::Number(20.0));
|
||||
assert_eq!(val(&s, "K2"), Value::Number(10.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_protection() {
|
||||
let mut s = sales();
|
||||
@@ -1062,6 +1368,34 @@ fn detail_cells_are_the_cells_show_details_takes() {
|
||||
assert!(crate::pivot::detail_cells(&d.wb, pt, d.wb.active_sheet()).unwrap_err().contains("out of date"));
|
||||
}
|
||||
|
||||
/// Measurement, not a check: `perf stat -e instructions:u` of this test with `PIVOT_BENCH_EDITS=0`
|
||||
/// and `=20` (and `PIVOT_BENCH_REOPEN=0/1`) gives the cost of edits on the report's sheet and of
|
||||
/// opening a saved workbook, with the setup subtracted. `PIVOT_BENCH_ROWS` is the source size.
|
||||
#[test]
|
||||
#[ignore = "measurement only"]
|
||||
fn bench_edit_on_sheet_with_large_report() {
|
||||
let env = |k: &str, d: usize| std::env::var(k).ok().and_then(|v| v.parse().ok()).unwrap_or(d);
|
||||
let (n, edits) = (env("PIVOT_BENCH_ROWS", 100_000), env("PIVOT_BENCH_EDITS", 0));
|
||||
let mut s = Session::new();
|
||||
s.new_workbook();
|
||||
let mut rows = vec![json!(["Id", "Product", "Sales"])];
|
||||
rows.extend((0..n).map(|i| {
|
||||
let (id, product) = (format!("id{i:07}"), ["Apples", "Pears", "Plums"][i % 3]);
|
||||
json!([id, product, i])
|
||||
}));
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": rows})).unwrap();
|
||||
s.execute("selection.set", json!({"range": "A1"})).unwrap();
|
||||
s.execute("insert.pivotTable", json!({"rows": ["Id"], "columns": ["Product"], "values": ["Sales"]})).unwrap();
|
||||
for i in 0..edits {
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": i.to_string()})).unwrap();
|
||||
}
|
||||
if env("PIVOT_BENCH_REOPEN", 0) == 1 {
|
||||
let wb = (*s.doc().unwrap().wb).clone();
|
||||
let (back, _) = gridcraft_xlsx::read_xlsx(&gridcraft_xlsx::write_xlsx(&wb).unwrap()).unwrap();
|
||||
s.add_document(crate::DocState::new(back, None, "Reopened".into(), crate::Trust::FromFile));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rank_ties_are_dense_and_count_numbers_is_captioned_count_of() {
|
||||
// #1448 items 10 and 12: Excel ranks 5, 4, 3, 3, 4 as 1, 2, 3, 3, 2 (GridCraft gave 1, 2, 4,
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::sync::Arc;
|
||||
|
||||
use gridcraft_core::{CellRef, MAX_COLS, MAX_ROWS, RangeRef};
|
||||
use gridcraft_formula::adjust::{Axis, Edit};
|
||||
use gridcraft_model::{Anchor, AnchorMode, Sheet, Visibility};
|
||||
use gridcraft_model::{Anchor, AnchorMode, PivotDataCell, PivotLookup, Sheet, Visibility};
|
||||
use serde_json::{Value as Json, json};
|
||||
|
||||
use super::{
|
||||
@@ -211,7 +211,31 @@ fn shift_sheet_features(sh: &mut Sheet, axis: Axis, at: u32, count: u32, insert:
|
||||
Axis::Rows => CellRef::new(at, pt.anchor.col),
|
||||
Axis::Cols => CellRef::new(pt.anchor.row, at),
|
||||
});
|
||||
pt.last_range = pt.last_range.and_then(map_range);
|
||||
let old = pt.last_range;
|
||||
pt.last_range = old.and_then(map_range);
|
||||
// GETPIVOTDATA's value cells are stored as offsets from the report's top-left cell, so
|
||||
// lines inserted or deleted inside the report move them as well. The moved cells go into
|
||||
// a new index (the shared one stays with the undo snapshots); a value cell deleted with
|
||||
// its line drops out, so it is #REF! rather than read from whatever took its place.
|
||||
let index = pt.data_index.clone();
|
||||
if let (Some(o), Some(n), Some(cells)) = (old, pt.last_range, index.cells()) {
|
||||
let (lo, hi) = if axis == Axis::Rows { (o.start.row, o.end.row) } else { (o.start.col, o.end.col) };
|
||||
let inside = at <= hi && if insert { at > lo } else { at.saturating_add(count) > lo };
|
||||
if inside {
|
||||
let moved: Vec<PivotDataCell> = cells
|
||||
.iter()
|
||||
.filter_map(|c| {
|
||||
let to = map_cell(CellRef::new(o.start.row.checked_add(c.row)?, o.start.col.checked_add(c.col)?))?;
|
||||
Some(PivotDataCell { row: to.row.checked_sub(n.start.row)?, col: to.col.checked_sub(n.start.col)?, ..c.clone() })
|
||||
})
|
||||
.collect();
|
||||
let lookup = PivotLookup::default();
|
||||
if !moved.is_empty() {
|
||||
lookup.set_cells(moved);
|
||||
}
|
||||
pt.data_index = lookup;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ impl FileKind {
|
||||
"ods" => FileKind::Ods,
|
||||
"csv" => FileKind::Csv,
|
||||
"tsv" | "tab" | "txt" => FileKind::Tsv,
|
||||
"json" | "scjson" => FileKind::Json,
|
||||
ext if craft_gridcraft_format::is_extension(ext) => FileKind::Json,
|
||||
"html" | "htm" => FileKind::Html,
|
||||
"slk" => FileKind::Sylk,
|
||||
_ => return None,
|
||||
@@ -316,7 +316,7 @@ fn read_plain(name: &str, bytes: &[u8], csv_as_text: bool) -> Result<(Workbook,
|
||||
}
|
||||
match kind {
|
||||
Some(FileKind::Json) => {
|
||||
let mut wb: Workbook = serde_json::from_slice(bytes).map_err(|e| EngineError::Other(format!("not a GridCraft JSON workbook: {e}")))?;
|
||||
let mut wb: Workbook = craft_gridcraft_format::read(bytes).map_err(|e| EngineError::Other(e.to_string()))?;
|
||||
wb.styles.rebuild_index();
|
||||
if wb.sheets.is_empty() {
|
||||
// The file's macros are read after this (`macros::load`), so they come along.
|
||||
|
||||
@@ -323,6 +323,7 @@ impl DocState {
|
||||
/// read from bytes (a file, a download, a recovery copy), [`Trust::Local`] only for a workbook
|
||||
/// made in this session.
|
||||
pub fn new(mut wb: Workbook, path: Option<String>, title: String, trust: Trust) -> DocState {
|
||||
let _ = gridcraft_model::PIVOT_INDEXER.set(pivot::index_cells);
|
||||
let mut calc = Calc::new();
|
||||
calc.recalc_all(&mut wb);
|
||||
Self::with_calc(wb, calc, path, title, trust)
|
||||
|
||||
@@ -213,17 +213,7 @@ pub fn json_bytes(wb: &Workbook) -> crate::Result<Vec<u8>> {
|
||||
for m in &wb.macros {
|
||||
check(m).map_err(crate::EngineError::Other)?;
|
||||
}
|
||||
let bytes = if wb.macros_unread.is_empty() {
|
||||
serde_json::to_vec_pretty(wb)
|
||||
} else {
|
||||
serde_json::to_value(wb).and_then(|mut v| {
|
||||
if let Some(list) = v.as_object_mut().map(|o| o.entry("macros").or_insert_with(|| Json::Array(vec![]))).and_then(Json::as_array_mut) {
|
||||
list.extend(wb.macros_unread.iter().cloned());
|
||||
}
|
||||
serde_json::to_vec_pretty(&v)
|
||||
})
|
||||
};
|
||||
bytes.map_err(|e| crate::EngineError::Other(e.to_string()))
|
||||
craft_gridcraft_format::write_with_kept(wb, "macros", &wb.macros_unread).map_err(|e| crate::EngineError::Other(e.to_string()))
|
||||
}
|
||||
|
||||
/// Whether `v` is a macro in a newer format than this build reads.
|
||||
|
||||
@@ -12,8 +12,8 @@ use gridcraft_core::date::datetime_from_serial;
|
||||
pub use gridcraft_core::quote_sheet;
|
||||
use gridcraft_core::{CellError, CellRef, MAX_COLS, MAX_ROWS, RangeRef, Value, split_sheet};
|
||||
use gridcraft_model::{
|
||||
BorderLine, BorderStyle, Cell, Chart, Color, Fill, HAlign, NumFmt, PivotDateGroup, PivotField, PivotFilter, PivotFunc, PivotLayout, PivotShowAs,
|
||||
PivotSort, PivotTable, PivotValue, Series, Style, StyleId, Workbook,
|
||||
BorderLine, BorderStyle, Cell, Chart, Color, Fill, HAlign, NumFmt, PivotDataCell, PivotDateGroup, PivotField, PivotFilter, PivotFunc,
|
||||
PivotItemRef, PivotLayout, PivotLookup, PivotShowAs, PivotSort, PivotTable, PivotValue, Series, Style, StyleId, Workbook,
|
||||
};
|
||||
|
||||
use crate::pivot_calc::CalcSet;
|
||||
@@ -41,6 +41,9 @@ pub const MAX_OUTPUT_CELLS: u64 = 2_000_000;
|
||||
pub const MAX_AXIS_FIELDS: usize = 32;
|
||||
/// Most fields in the Values area.
|
||||
pub const MAX_VALUE_FIELDS: usize = 256;
|
||||
/// Most report value cells a report may have (every one is indexed for GETPIVOTDATA; bigger
|
||||
/// reports are rejected).
|
||||
pub const MAX_INDEXED_CELLS: usize = 1_000_000;
|
||||
|
||||
const MONTHS: [&str; 12] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||||
|
||||
@@ -314,9 +317,42 @@ pub fn refresh(wb: &mut Workbook, sheet: usize, idx: usize, replace: bool) -> Re
|
||||
}
|
||||
let sheet_name = shm.name.clone();
|
||||
rebind_charts(wb, &sheet_name, &pt.name, origin, &out);
|
||||
// The index of the new report; its lookup hash is built on the first GETPIVOTDATA.
|
||||
if let Some(p) = wb.sheet_mut(sheet).and_then(|s| s.pivots.get_mut(idx)) {
|
||||
let index = PivotLookup::default();
|
||||
index.set_cells(out.data);
|
||||
p.data_index = index;
|
||||
}
|
||||
Ok(area)
|
||||
}
|
||||
|
||||
/// The value cells of a PivotTable's report, for GETPIVOTDATA when a refresh did not set the
|
||||
/// index (a workbook just opened from XLSX). The positions must describe the report as it is
|
||||
/// stored on the sheet, not as the current source would render it: the source is recomputed only
|
||||
/// to learn the layout, and the result is accepted when every label and header cell of that
|
||||
/// layout equals the stored cell at the same place. A source changed since the last refresh gives
|
||||
/// a different layout, so there is no trustworthy index and the lookup fails until a refresh.
|
||||
pub fn index_cells(wb: &Workbook, sheet: usize, pt: &PivotTable) -> Result<Vec<PivotDataCell>, String> {
|
||||
const STALE: &str = "The stored report no longer matches the source. Refresh the PivotTable.";
|
||||
let report = pt.last_range.ok_or("The PivotTable has no report.")?;
|
||||
let out = compute(wb, pt, sheet)?;
|
||||
let sh = wb.sheet(sheet).ok_or("There's no such sheet.")?;
|
||||
let rows = u64::from(report.end.row) - u64::from(report.start.row) + 1;
|
||||
let cols = u64::from(report.end.col) - u64::from(report.start.col) + 1;
|
||||
if rows != u64::from(out.height().max(1)) || cols != u64::from(out.width.max(1)) {
|
||||
return Err(STALE.into());
|
||||
}
|
||||
let labels = [CellKind::Header, CellKind::RowLabel, CellKind::ColLabel, CellKind::Filter];
|
||||
for (r, row) in out.grid.iter().enumerate() {
|
||||
for (c, oc) in row.iter().enumerate() {
|
||||
if labels.contains(&oc.kind) && sh.value(CellRef::new(report.start.row + r as u32, report.start.col + c as u32)) != oc.value {
|
||||
return Err(STALE.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(out.data)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod fit_tests {
|
||||
use super::data_cols_exceed_sheet;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::output::Output;
|
||||
use super::{CellRef, Chart, Series, Workbook, quote_sheet};
|
||||
use super::{CellRef, Chart, PivotLookup, Series, Workbook, quote_sheet};
|
||||
|
||||
// ---------------------------------------------------------------- PivotCharts
|
||||
|
||||
@@ -109,6 +109,7 @@ pub fn clear_output(wb: &mut Workbook, sheet: usize, idx: usize) {
|
||||
shm.take_cells(r);
|
||||
if let Some(p) = shm.pivots.get_mut(idx) {
|
||||
p.last_range = None;
|
||||
p.data_index = PivotLookup::default();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +127,7 @@ mod tests {
|
||||
chart_rows: vec![1, 2, 3],
|
||||
chart_cols: (1..1000).map(|c| (c, format!("S{c}"))).collect(),
|
||||
label_col: Some(0),
|
||||
data: vec![],
|
||||
};
|
||||
assert_eq!(chart_series("Sheet1", CellRef::new(0, 0), &out).len(), MAX_CHART_SERIES);
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ use super::output::{
|
||||
AggMap, CellKind, ColKind, ColSpec, Ctx, Grid, Line, LineKind, Output, RowKind, ValSrc, caption, data_cols_exceed_sheet, flatten_cols,
|
||||
};
|
||||
use super::{
|
||||
CalcSet, CellError, CellRef, HashMap, HashSet, MAX_AXIS_FIELDS, MAX_COLS, MAX_VALUE_FIELDS, PivotDateGroup, PivotField, PivotFilter, PivotFunc,
|
||||
PivotLayout, PivotShowAs, PivotTable, PivotValue, Source, Value, Workbook, read_source,
|
||||
CalcSet, CellError, CellRef, HashMap, HashSet, MAX_AXIS_FIELDS, MAX_COLS, MAX_INDEXED_CELLS, MAX_VALUE_FIELDS, PivotDataCell, PivotDateGroup,
|
||||
PivotField, PivotFilter, PivotFunc, PivotItemRef, PivotLayout, PivotShowAs, PivotTable, PivotValue, Source, Value, Workbook, read_source,
|
||||
};
|
||||
|
||||
/// Why Show Details turns a cell down when it isn't a value cell of a PivotTable (the front end
|
||||
@@ -653,6 +653,7 @@ pub(super) fn compute_from(wb: &Workbook, pt: &PivotTable, src: &Source, mut pro
|
||||
chart_rows: vec![],
|
||||
chart_cols: vec![],
|
||||
label_col: None,
|
||||
data: vec![],
|
||||
});
|
||||
}
|
||||
|
||||
@@ -728,6 +729,16 @@ pub(super) fn compute_from(wb: &Workbook, pt: &PivotTable, src: &Source, mut pro
|
||||
} else {
|
||||
Some(row_levels.saturating_sub(1) as u32)
|
||||
};
|
||||
let item_refs = |fields: &[&PivotField], items: &[FieldItems], path: &[u32]| -> Vec<PivotItemRef> {
|
||||
path.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(d, it)| {
|
||||
let (f, item) = (fields.get(d)?, items.get(d)?.get(*it)?);
|
||||
Some(PivotItemRef { field: f.source_col.clone(), label: item.label.clone(), value: item.value.clone() })
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let mut data: Vec<PivotDataCell> = Vec::new();
|
||||
for line in &lines {
|
||||
let rk = match line.kind {
|
||||
LineKind::Item(b) => RowKind::Item(b),
|
||||
@@ -758,6 +769,21 @@ pub(super) fn compute_from(wb: &Workbook, pt: &PivotTable, src: &Source, mut pro
|
||||
let Some(raw) = lookup.get(rp, cp, *vi) else { continue };
|
||||
let context = ShowContext { row_path: rp, col_path: cp, value_index: *vi, level0: &level0, siblings: &siblings, cache: &show_cache };
|
||||
let shown = show_value(vdef, raw, &lookup, &context);
|
||||
// Every value cell of the report is indexed, so a report that needs more cells than
|
||||
// the index cap is rejected outright — never written with a truncated index that
|
||||
// would answer #REF! for the values the sheet shows.
|
||||
if data.len() >= MAX_INDEXED_CELLS {
|
||||
return Err(format!("A PivotTable report can have at most {MAX_INDEXED_CELLS} value cells."));
|
||||
}
|
||||
let mut items = item_refs(&ctx.rows, &ctx.row_items, rp);
|
||||
items.extend(item_refs(&col_fields, &col_items, cp));
|
||||
data.push(PivotDataCell {
|
||||
data_field: vdef.name.clone(),
|
||||
source_col: vdef.source_col.clone(),
|
||||
items,
|
||||
row: u32::try_from(r).unwrap_or(u32::MAX),
|
||||
col: u32::try_from(l + j).unwrap_or(u32::MAX),
|
||||
});
|
||||
if let Some(pr) = probe.as_deref_mut() {
|
||||
if pr.at == Some((r, l + j)) {
|
||||
pr.hit = Some((rp.to_vec(), cp.to_vec()));
|
||||
@@ -769,5 +795,5 @@ pub(super) fn compute_from(wb: &Workbook, pt: &PivotTable, src: &Source, mut pro
|
||||
g.set(r, l + j, shown, ck.1, 0, data_fmt.get(*vi).cloned().flatten());
|
||||
}
|
||||
}
|
||||
Ok(Output { width: g.width as u32, grid: g.rows, row_kinds: g.kinds, body_offset, chart_rows, chart_cols, label_col })
|
||||
Ok(Output { width: g.width as u32, grid: g.rows, row_kinds: g.kinds, body_offset, chart_rows, chart_cols, label_col, data })
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::items::{Acc, FieldItems, Node, is_collapsed};
|
||||
use super::{
|
||||
BorderLine, BorderStyle, Color, Fill, HAlign, HashMap, MAX_COLS, MAX_OUTPUT_CELLS, MAX_ROWS, NumFmt, PivotField, PivotLayout, PivotTable, Style,
|
||||
Value,
|
||||
BorderLine, BorderStyle, Color, Fill, HAlign, HashMap, MAX_COLS, MAX_OUTPUT_CELLS, MAX_ROWS, NumFmt, PivotDataCell, PivotField, PivotLayout,
|
||||
PivotTable, Style, Value,
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------- output
|
||||
@@ -61,6 +61,8 @@ pub struct Output {
|
||||
pub chart_cols: Vec<(u32, String)>,
|
||||
/// Grid column holding the innermost row labels (`None` without row fields).
|
||||
pub label_col: Option<u32>,
|
||||
/// Every value cell with the items that locate it (for GETPIVOTDATA).
|
||||
pub data: Vec<PivotDataCell>,
|
||||
}
|
||||
|
||||
impl Output {
|
||||
|
||||
+134
-1
@@ -1621,6 +1621,44 @@ fn case_sensitive_sort_puts_lowercase_first() {
|
||||
assert_eq!(col, ["a", "A", "aB", "Ab", "b", "B"].map(Value::from));
|
||||
}
|
||||
|
||||
/// #3949: Excel sorts values that are not in the custom list A to Z after the listed ones.
|
||||
#[test]
|
||||
fn custom_list_sort_puts_unlisted_values_after_the_list_in_order() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["Priority"], ["Zulu"], ["Alpha"], ["Low"], ["High"], ["Medium"]]})).unwrap();
|
||||
let key = json!({"column": "A", "order": "asc", "customList": ["High", "Medium", "Low"]});
|
||||
s.execute("data.sort", json!({"range": "A1:A6", "header": true, "keys": [key]})).unwrap();
|
||||
let col: Vec<Value> = (1..=6).map(|r| v(&s, &format!("A{r}"))).collect();
|
||||
assert_eq!(col, ["Priority", "High", "Medium", "Low", "Alpha", "Zulu"].map(Value::from));
|
||||
}
|
||||
|
||||
/// #3949 changes only an ascending custom-list key: with a descending one, two values not in the
|
||||
/// list still tie, so the next key orders them.
|
||||
#[test]
|
||||
fn descending_custom_list_sort_leaves_unlisted_values_to_the_next_key() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["Name", "N"], ["Zulu", 2], ["Alpha", 1], ["High", 3]]})).unwrap();
|
||||
let keys = json!([
|
||||
{"column": "A", "order": "desc", "customList": ["High", "Medium", "Low"]},
|
||||
{"column": "B", "order": "asc"}
|
||||
]);
|
||||
s.execute("data.sort", json!({"range": "A1:B4", "header": true, "keys": keys})).unwrap();
|
||||
let col: Vec<Value> = (2..=4).map(|r| v(&s, &format!("A{r}"))).collect();
|
||||
assert_eq!(col, ["Alpha", "Zulu", "High"].map(Value::from));
|
||||
}
|
||||
|
||||
/// A blank in a descending custom-list key goes last, after the list, rather than tying with the
|
||||
/// values that are not in the list (which come first), so the order is the same whatever the input.
|
||||
#[test]
|
||||
fn descending_custom_list_sort_puts_blanks_last() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["Name"], [null], ["High"], ["Zulu"]]})).unwrap();
|
||||
let key = json!({"column": "A", "order": "desc", "customList": ["High", "Medium", "Low"]});
|
||||
s.execute("data.sort", json!({"range": "A1:A4", "header": true, "keys": [key]})).unwrap();
|
||||
let col: Vec<Value> = (2..=4).map(|r| v(&s, &format!("A{r}"))).collect();
|
||||
assert_eq!(col, [Value::from("Zulu"), Value::from("High"), Value::Empty]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn data_sort_orders_vowelled_arabic_by_letters() {
|
||||
let mut s = s();
|
||||
@@ -1759,7 +1797,7 @@ fn subtotal_with_a_sheet_prefix_works_on_the_named_sheet() {
|
||||
assert_eq!(col(prices, 0), ["Item", "a", "a", "a Total", "b", "b Total", "Grand Total"].map(Value::from));
|
||||
assert_eq!(col(prices, 1)[1..], [1.0, 2.0, 3.0, 4.0, 4.0, 7.0].map(Value::from));
|
||||
assert!(wb.styles.get(prices.style_id(CellRef::new(3, 0))).font.bold);
|
||||
assert_eq!(prices.rows.get(&1).map(|l| l.outline), Some(1));
|
||||
assert_eq!(prices.rows.get(&1).map(|l| l.outline), Some(2));
|
||||
let sheet1 = wb.sheet(wb.sheet_index("Sheet1").unwrap()).unwrap();
|
||||
assert_eq!(col(sheet1, 0)[..4], ["Name", "x", "x", "y"].map(Value::from));
|
||||
assert!(sheet1.value(CellRef::new(4, 0)).is_empty());
|
||||
@@ -1767,6 +1805,24 @@ fn subtotal_with_a_sheet_prefix_works_on_the_named_sheet() {
|
||||
assert!(s.execute("data.group", json!({"sheet": "Prices"})).is_err());
|
||||
}
|
||||
|
||||
/// #3945: Excel groups every data and subtotal row under the grand total, so the details are at
|
||||
/// level 2, the subtotals at level 1, and showing level 1 leaves only the grand total.
|
||||
#[test]
|
||||
fn subtotal_groups_everything_under_the_grand_total() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [["Group", "Amount"], ["A", 10], ["A", 20], ["B", 30]]})).unwrap();
|
||||
s.execute("data.subtotal", json!({"range": "A1:B4", "groupBy": "A", "columns": ["B"], "function": "sum"})).unwrap();
|
||||
let sh = s.doc().unwrap().wb.active().unwrap();
|
||||
let levels: Vec<u8> = (0..7).map(|r| sh.rows.get(&r).map_or(0, |l| l.outline)).collect();
|
||||
assert_eq!(levels, [0, 2, 2, 1, 2, 1, 0]);
|
||||
let shown = |s: &Session| -> Vec<u32> { (0..7).filter(|&r| !s.doc().unwrap().wb.active().unwrap().is_row_hidden(r)).map(|r| r + 1).collect() };
|
||||
s.execute("data.showLevels", json!({"rows": 1})).unwrap();
|
||||
assert_eq!(shown(&s), [1, 7]);
|
||||
s.execute("data.showLevels", json!({"rows": 2})).unwrap();
|
||||
assert_eq!(shown(&s), [1, 4, 6, 7]);
|
||||
assert_eq!(v(&s, "B7"), Value::Number(60.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn formatting_and_styles() {
|
||||
let mut s = s();
|
||||
@@ -2401,6 +2457,35 @@ fn merging_over_a_spill_blocks_it_and_unmerging_unblocks_it() {
|
||||
assert_eq!(v(&s, "A3"), Value::Number(3.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inserting_a_link_without_text_preserves_a_spill_child() {
|
||||
let mut s = s();
|
||||
s.execute("cell.set", json!({"cell": "A1", "input": "=SEQUENCE(3)"})).unwrap();
|
||||
assert_eq!(v(&s, "A2"), Value::Number(2.0));
|
||||
s.execute("insert.link", json!({"cell": "A2", "target": "https://example.org"})).unwrap();
|
||||
assert_eq!(v(&s, "A1"), Value::Number(1.0));
|
||||
assert_eq!(v(&s, "A2"), Value::Number(2.0));
|
||||
let d = s.doc().unwrap();
|
||||
let at = CellRef::parse("A2").unwrap();
|
||||
assert_eq!(d.wb.active().unwrap().hyperlinks.get(&at).map(|link| link.target.as_str()), Some("https://example.org"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inserting_a_link_without_text_preserves_an_empty_spill_child() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1:C3", "values": [["a", "x", 1], ["b", "x", 2], ["a", "y", 3]]})).unwrap();
|
||||
s.execute("cell.set", json!({"cell": "K1", "input": "=PIVOTBY(A1:A3,B1:B3,C1:C3,LAMBDA(x,SUM(x)))"})).unwrap();
|
||||
assert_eq!(v(&s, "K1"), Value::Empty);
|
||||
let at = CellRef::parse("M3").unwrap();
|
||||
assert_eq!(v(&s, "M3"), Value::Empty);
|
||||
assert_eq!(s.doc().unwrap().wb.active().unwrap().spill_anchor(at), Some(CellRef::parse("K1").unwrap()));
|
||||
s.execute("insert.link", json!({"cell": "M3", "target": "https://example.org"})).unwrap();
|
||||
assert_eq!(v(&s, "K1"), Value::Empty);
|
||||
assert_eq!(v(&s, "M3"), Value::Empty);
|
||||
let d = s.doc().unwrap();
|
||||
assert_eq!(d.wb.active().unwrap().hyperlinks.get(&at).map(|link| link.target.as_str()), Some("https://example.org"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_cell_array_formulas_and_tables_dont_overlap() {
|
||||
// Found by the command-sequence fuzzer: an array over a table header lost its value to the
|
||||
@@ -5751,6 +5836,53 @@ fn tiled_paste_clears_destination_cells_under_blank_source_cells() {
|
||||
assert_eq!(v(&s, "C4"), Value::Empty);
|
||||
}
|
||||
|
||||
/// #3934: a row copied into a taller, narrower selection repeats down every selected row at the
|
||||
/// copy's width, as in Excel; a column copied into a wider, shorter one repeats across.
|
||||
#[test]
|
||||
fn paste_into_a_narrower_selection_repeats_the_copy_down_its_rows() {
|
||||
for dest in ["A3:A6", "A3:B6"] {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [[1, 2]]})).unwrap();
|
||||
s.execute("edit.copy", json!({"range": "A1:B1"})).unwrap();
|
||||
s.execute("selection.set", json!({"range": dest})).unwrap();
|
||||
let r = s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(r["pasted"], json!("A3:B6"), "{dest}");
|
||||
for row in 3..=6 {
|
||||
assert_eq!(v(&s, &format!("A{row}")), Value::Number(1.0), "{dest} row {row}");
|
||||
assert_eq!(v(&s, &format!("B{row}")), Value::Number(2.0), "{dest} row {row}");
|
||||
}
|
||||
assert_eq!(v(&s, "A2"), Value::Empty);
|
||||
assert_eq!(v(&s, "A7"), Value::Empty);
|
||||
}
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [[1], [2]]})).unwrap();
|
||||
s.execute("edit.copy", json!({"range": "A1:A2"})).unwrap();
|
||||
s.execute("selection.set", json!({"range": "C1:F1"})).unwrap();
|
||||
let r = s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(r["pasted"], json!("C1:F2"));
|
||||
for col in ["C", "D", "E", "F"] {
|
||||
assert_eq!(v(&s, &format!("{col}1")), Value::Number(1.0), "{col}1");
|
||||
assert_eq!(v(&s, &format!("{col}2")), Value::Number(2.0), "{col}2");
|
||||
}
|
||||
}
|
||||
|
||||
/// #3934: repeating a wide copy down a narrow selection writes the copy's width on every row, so
|
||||
/// the 4,000,000-cell limit on a tiled paste counts that area, not the selection's. Past it the
|
||||
/// copy is pasted once, as a tiled paste over too large a selection already is.
|
||||
#[test]
|
||||
fn a_row_repeated_down_a_narrow_selection_is_bounded_by_the_area_it_fills() {
|
||||
let mut s = s();
|
||||
s.execute("range.setValues", json!({"range": "A1", "values": [[1]]})).unwrap();
|
||||
s.execute("range.setValues", json!({"range": "P1", "values": [[2]]})).unwrap();
|
||||
s.execute("edit.copy", json!({"range": "A1:P1"})).unwrap();
|
||||
// 300,000 rows selected, 4,800,000 cells once the copy's 16 columns are repeated down them.
|
||||
s.execute("selection.set", json!({"range": "A3:A300002"})).unwrap();
|
||||
let r = s.execute("edit.paste", json!({})).unwrap();
|
||||
assert_eq!(r["pasted"], json!("A3:P3"));
|
||||
assert_eq!(v(&s, "P3"), Value::Number(2.0));
|
||||
assert_eq!(v(&s, "A4"), Value::Empty);
|
||||
}
|
||||
|
||||
/// Excel refuses a paste that would run off the sheet rather than pasting part of it: whole
|
||||
/// columns below row 1, whole rows right of column A, a whole column transposed, or a block at
|
||||
/// the last row or column.
|
||||
@@ -6494,6 +6626,7 @@ fn a_script_cannot_switch_windows() {
|
||||
|
||||
mod controls;
|
||||
mod equation;
|
||||
mod json_golden;
|
||||
mod macros;
|
||||
mod objects;
|
||||
mod python_cells;
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//! Byte-for-byte checks on the native JSON workbook (`.json`, `.scjson`). The files in
|
||||
//! `crates/engine/tests/golden` were written before the format moved to `craft-gridcraft-format`
|
||||
//! (storytold/craft-libs). Saving the same workbook must give the same bytes, and opening a
|
||||
//! golden file and saving it again must give it back.
|
||||
//! `GRIDCRAFT_BLESS_GOLDEN=1` rewrites them. Only do that for a deliberate format change.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use super::s;
|
||||
use crate::Session;
|
||||
|
||||
fn golden(name: &str) -> PathBuf {
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests").join("golden").join(name)
|
||||
}
|
||||
|
||||
fn check(name: &str, actual: &[u8]) {
|
||||
let path = golden(name);
|
||||
if std::env::var_os("GRIDCRAFT_BLESS_GOLDEN").is_some() {
|
||||
std::fs::write(&path, actual).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
||||
return;
|
||||
}
|
||||
let expected = std::fs::read(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()));
|
||||
assert!(expected == actual, "{name} changed ({} bytes, golden has {})", actual.len(), expected.len());
|
||||
}
|
||||
|
||||
fn save(s: &mut Session) -> Vec<u8> {
|
||||
let r = s.execute("file.saveBytes", json!({"format": "json"})).unwrap();
|
||||
crate::io::base64_decode(r["base64"].as_str().unwrap()).unwrap()
|
||||
}
|
||||
|
||||
fn open(s: &mut Session, name: &str, bytes: &[u8]) {
|
||||
s.execute("file.open", json!({"name": name, "base64": crate::io::base64_encode(bytes)})).unwrap();
|
||||
}
|
||||
|
||||
/// A workbook with text, numbers, a formula, a style, a number format, a second sheet and a macro.
|
||||
fn book() -> Session {
|
||||
let mut s = s();
|
||||
for (cell, input) in [("A1", "Item"), ("B1", "Qty"), ("A2", "Äpfel ✓"), ("B2", "3.5"), ("A3", "Pears"), ("B3", "2"), ("B4", "=SUM(B2:B3)")] {
|
||||
s.execute("cell.set", json!({"cell": cell, "input": input})).unwrap();
|
||||
}
|
||||
s.execute("home.bold", json!({"range": "A1:B1"})).unwrap();
|
||||
s.execute("home.numberFormat", json!({"range": "B2:B4", "format": "0.00"})).unwrap();
|
||||
s.execute("macro.save", json!({"name": "Fill", "steps": [{"command": "cell.set", "params": {"cell": "C1", "input": "x"}}]})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_save_writes_the_golden_workbook_bytes() {
|
||||
let mut s = book();
|
||||
check("book.json", &save(&mut s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_golden_workbook_opens_and_saves_back_unchanged() {
|
||||
let bytes = std::fs::read(golden("book.json")).unwrap();
|
||||
for name in ["book.json", "book.scjson"] {
|
||||
let mut s = s();
|
||||
open(&mut s, name, &bytes);
|
||||
assert_eq!(super::v(&s, "B4"), gridcraft_core::Value::Number(5.5), "{name}");
|
||||
assert!(save(&mut s) == bytes, "{name} saved back differently");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macros_in_a_newer_format_are_written_back_as_the_file_held_them() {
|
||||
// The save that splices kept macros back into `macros` goes through a JSON value.
|
||||
let mut v: serde_json::Value = serde_json::from_slice(&std::fs::read(golden("book.json")).unwrap()).unwrap();
|
||||
v["macros"].as_array_mut().unwrap().push(json!({"name": "Future", "v": gridcraft_model::MACRO_VERSION + 1, "extra": [1, 2]}));
|
||||
let mut s = s();
|
||||
open(&mut s, "kept.json", &serde_json::to_vec_pretty(&v).unwrap());
|
||||
check("kept.json", &save(&mut s));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn what_is_not_a_json_workbook_says_so() {
|
||||
let err = crate::io::open_bytes("bad.json", b"{\"sheets\": 7}").unwrap_err().to_string();
|
||||
check("bad.error.txt", err.as_bytes());
|
||||
}
|
||||
@@ -530,3 +530,16 @@ fn python_code_with_an_empty_value_counts_as_content() {
|
||||
s.execute("edit.copy", json!({"range": "T1"})).unwrap();
|
||||
assert!(s.execute("edit.paste", json!({"at": "R2"})).is_err_and(|e| e.to_string().contains("part of an array")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inserting_a_link_without_text_preserves_an_empty_python_cell() {
|
||||
let mut s = s();
|
||||
plant_empty(&mut s, "A1");
|
||||
s.execute("insert.link", json!({"cell": "A1", "target": "https://example.org"})).unwrap();
|
||||
assert_eq!(code(&s, 0, "A1"), Some("x = 1".into()));
|
||||
let d = s.doc().unwrap();
|
||||
let sh = d.wb.sheet(0).unwrap();
|
||||
let at = CellRef::parse("A1").unwrap();
|
||||
assert_eq!(sh.value(at), Value::Empty);
|
||||
assert_eq!(sh.hyperlinks.get(&at).map(|link| link.target.as_str()), Some("https://example.org"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
# Golden files are compared byte for byte: no line-ending conversion on checkout.
|
||||
* -text
|
||||
@@ -0,0 +1 @@
|
||||
not a GridCraft JSON workbook: invalid type: integer `7`, expected a sequence at line 1 column 12
|
||||
@@ -0,0 +1,440 @@
|
||||
{
|
||||
"sheets": [
|
||||
{
|
||||
"name": "Sheet1",
|
||||
"cells": {
|
||||
"bands": {
|
||||
"0": {
|
||||
"rows": {
|
||||
"0": {
|
||||
"0": {
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Item"
|
||||
},
|
||||
"formula": null,
|
||||
"style": 1
|
||||
},
|
||||
"1": {
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Qty"
|
||||
},
|
||||
"formula": null,
|
||||
"style": 1
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"0": {
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Äpfel ✓"
|
||||
},
|
||||
"formula": null,
|
||||
"style": 0
|
||||
},
|
||||
"1": {
|
||||
"value": {
|
||||
"t": "Number",
|
||||
"v": 3.5
|
||||
},
|
||||
"formula": null,
|
||||
"style": 2
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"0": {
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Pears"
|
||||
},
|
||||
"formula": null,
|
||||
"style": 0
|
||||
},
|
||||
"1": {
|
||||
"value": {
|
||||
"t": "Number",
|
||||
"v": 2.0
|
||||
},
|
||||
"formula": null,
|
||||
"style": 2
|
||||
}
|
||||
},
|
||||
"3": {
|
||||
"1": {
|
||||
"value": {
|
||||
"t": "Number",
|
||||
"v": 5.5
|
||||
},
|
||||
"formula": {
|
||||
"text": "SUM(B2:B3)",
|
||||
"array": null
|
||||
},
|
||||
"style": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"len": 7
|
||||
},
|
||||
"cols": {},
|
||||
"rows": {},
|
||||
"default_col_width": 64.0,
|
||||
"default_row_height": 20.0,
|
||||
"merges": [],
|
||||
"freeze": null,
|
||||
"tab_color": null,
|
||||
"visibility": "Visible",
|
||||
"show_gridlines": true,
|
||||
"show_headings": true,
|
||||
"show_formulas": false,
|
||||
"show_zeros": true,
|
||||
"show_outline_symbols": true,
|
||||
"summary_below": true,
|
||||
"summary_right": true,
|
||||
"right_to_left": false,
|
||||
"zoom": 100,
|
||||
"cond_formats": [],
|
||||
"validations": [],
|
||||
"tables": [],
|
||||
"autofilter": null,
|
||||
"comments": {},
|
||||
"hyperlinks": {},
|
||||
"charts": [],
|
||||
"images": [],
|
||||
"shapes": [],
|
||||
"sparklines": [],
|
||||
"slicers": [],
|
||||
"pivots": [],
|
||||
"protection": null,
|
||||
"print": {
|
||||
"orientation": "Portrait",
|
||||
"paper": "Letter",
|
||||
"margins": [
|
||||
0.7,
|
||||
0.7,
|
||||
0.75,
|
||||
0.75,
|
||||
0.3,
|
||||
0.3
|
||||
],
|
||||
"print_area": null,
|
||||
"title_rows": null,
|
||||
"title_cols": null,
|
||||
"scale": 100,
|
||||
"fit_to": null,
|
||||
"gridlines": false,
|
||||
"headings": false,
|
||||
"center_h": false,
|
||||
"center_v": false,
|
||||
"header": "",
|
||||
"footer": "",
|
||||
"row_breaks": [],
|
||||
"col_breaks": [],
|
||||
"different_first": false,
|
||||
"different_odd_even": false,
|
||||
"first_header": "",
|
||||
"first_footer": "",
|
||||
"even_header": "",
|
||||
"even_footer": "",
|
||||
"hf_scale_with_doc": true,
|
||||
"hf_align_with_margins": true,
|
||||
"page_order": "downThenOver"
|
||||
},
|
||||
"view_active": {
|
||||
"row": 0,
|
||||
"col": 0
|
||||
},
|
||||
"view_top_left": {
|
||||
"row": 0,
|
||||
"col": 0
|
||||
},
|
||||
"view": "normal"
|
||||
}
|
||||
],
|
||||
"names": [],
|
||||
"styles": {
|
||||
"styles": [
|
||||
{
|
||||
"font": {
|
||||
"name": "Calibri",
|
||||
"size": 11.0,
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"underline": "None",
|
||||
"strike": false,
|
||||
"color": "Auto",
|
||||
"vert": "Baseline",
|
||||
"charset": null,
|
||||
"family": null,
|
||||
"minor": true
|
||||
},
|
||||
"fill": {
|
||||
"pattern": "None",
|
||||
"fg": "Auto",
|
||||
"bg": "Auto"
|
||||
},
|
||||
"borders": {
|
||||
"left": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"right": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"top": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"bottom": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"diag_down": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"diag_up": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
}
|
||||
},
|
||||
"align": {
|
||||
"h": "General",
|
||||
"v": "Bottom",
|
||||
"wrap": false,
|
||||
"shrink": false,
|
||||
"indent": 0,
|
||||
"rotation": 0,
|
||||
"reading_order": null
|
||||
},
|
||||
"num_fmt": "General",
|
||||
"protection": {
|
||||
"locked": true,
|
||||
"hidden": false
|
||||
},
|
||||
"dxf_stated": {
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"strike": false,
|
||||
"underline": false,
|
||||
"size": false,
|
||||
"name": false,
|
||||
"scheme": null,
|
||||
"protection": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"font": {
|
||||
"name": "Calibri",
|
||||
"size": 11.0,
|
||||
"bold": true,
|
||||
"italic": false,
|
||||
"underline": "None",
|
||||
"strike": false,
|
||||
"color": "Auto",
|
||||
"vert": "Baseline",
|
||||
"charset": null,
|
||||
"family": null,
|
||||
"minor": true
|
||||
},
|
||||
"fill": {
|
||||
"pattern": "None",
|
||||
"fg": "Auto",
|
||||
"bg": "Auto"
|
||||
},
|
||||
"borders": {
|
||||
"left": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"right": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"top": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"bottom": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"diag_down": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"diag_up": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
}
|
||||
},
|
||||
"align": {
|
||||
"h": "General",
|
||||
"v": "Bottom",
|
||||
"wrap": false,
|
||||
"shrink": false,
|
||||
"indent": 0,
|
||||
"rotation": 0,
|
||||
"reading_order": null
|
||||
},
|
||||
"num_fmt": "General",
|
||||
"protection": {
|
||||
"locked": true,
|
||||
"hidden": false
|
||||
},
|
||||
"dxf_stated": {
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"strike": false,
|
||||
"underline": false,
|
||||
"size": false,
|
||||
"name": false,
|
||||
"scheme": null,
|
||||
"protection": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"font": {
|
||||
"name": "Calibri",
|
||||
"size": 11.0,
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"underline": "None",
|
||||
"strike": false,
|
||||
"color": "Auto",
|
||||
"vert": "Baseline",
|
||||
"charset": null,
|
||||
"family": null,
|
||||
"minor": true
|
||||
},
|
||||
"fill": {
|
||||
"pattern": "None",
|
||||
"fg": "Auto",
|
||||
"bg": "Auto"
|
||||
},
|
||||
"borders": {
|
||||
"left": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"right": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"top": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"bottom": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"diag_down": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
},
|
||||
"diag_up": {
|
||||
"style": "None",
|
||||
"color": "Auto"
|
||||
}
|
||||
},
|
||||
"align": {
|
||||
"h": "General",
|
||||
"v": "Bottom",
|
||||
"wrap": false,
|
||||
"shrink": false,
|
||||
"indent": 0,
|
||||
"rotation": 0,
|
||||
"reading_order": null
|
||||
},
|
||||
"num_fmt": "0.00",
|
||||
"protection": {
|
||||
"locked": true,
|
||||
"hidden": false
|
||||
},
|
||||
"dxf_stated": {
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"strike": false,
|
||||
"underline": false,
|
||||
"size": false,
|
||||
"name": false,
|
||||
"scheme": null,
|
||||
"protection": false
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"theme": {
|
||||
"name": "Craft",
|
||||
"colors": [
|
||||
16777215,
|
||||
0,
|
||||
15263976,
|
||||
927809,
|
||||
1400962,
|
||||
15298866,
|
||||
1665828,
|
||||
1023701,
|
||||
10496915,
|
||||
5154606,
|
||||
4618374,
|
||||
9855101
|
||||
],
|
||||
"major_font": "Calibri",
|
||||
"minor_font": "Calibri",
|
||||
"major_font_ea": "",
|
||||
"minor_font_ea": "",
|
||||
"major_font_cs": "",
|
||||
"minor_font_cs": "",
|
||||
"major_font_scripts": [],
|
||||
"minor_font_scripts": []
|
||||
},
|
||||
"date_system": "D1900",
|
||||
"calc": {
|
||||
"mode": "Automatic",
|
||||
"iterative": false,
|
||||
"max_iterations": 100,
|
||||
"max_change": 0.001,
|
||||
"precision_as_displayed": false,
|
||||
"r1c1": false
|
||||
},
|
||||
"active_sheet": 0,
|
||||
"props": {
|
||||
"title": "",
|
||||
"subject": "",
|
||||
"author": "GridCraft User",
|
||||
"company": "",
|
||||
"keywords": "",
|
||||
"description": ""
|
||||
},
|
||||
"protected_structure": false,
|
||||
"custom_lists": [],
|
||||
"cell_styles": [],
|
||||
"vba_project": null,
|
||||
"macros": [
|
||||
{
|
||||
"v": 1,
|
||||
"name": "Fill",
|
||||
"description": "",
|
||||
"inputs": [],
|
||||
"steps": [
|
||||
{
|
||||
"type": "command",
|
||||
"id": "cell.set",
|
||||
"params": {
|
||||
"cell": "C1",
|
||||
"input": "x"
|
||||
}
|
||||
}
|
||||
],
|
||||
"output": {
|
||||
"onConflict": "ask"
|
||||
},
|
||||
"permissions": []
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,448 @@
|
||||
{
|
||||
"active_sheet": 0,
|
||||
"calc": {
|
||||
"iterative": false,
|
||||
"max_change": 0.001,
|
||||
"max_iterations": 100,
|
||||
"mode": "Automatic",
|
||||
"precision_as_displayed": false,
|
||||
"r1c1": false
|
||||
},
|
||||
"cell_styles": [],
|
||||
"custom_lists": [],
|
||||
"date_system": "D1900",
|
||||
"macros": [
|
||||
{
|
||||
"description": "",
|
||||
"inputs": [],
|
||||
"name": "Fill",
|
||||
"output": {
|
||||
"onConflict": "ask"
|
||||
},
|
||||
"permissions": [],
|
||||
"steps": [
|
||||
{
|
||||
"id": "cell.set",
|
||||
"params": {
|
||||
"cell": "C1",
|
||||
"input": "x"
|
||||
},
|
||||
"type": "command"
|
||||
}
|
||||
],
|
||||
"v": 1
|
||||
},
|
||||
{
|
||||
"extra": [
|
||||
1,
|
||||
2
|
||||
],
|
||||
"name": "Future",
|
||||
"v": 2
|
||||
}
|
||||
],
|
||||
"names": [],
|
||||
"props": {
|
||||
"author": "GridCraft User",
|
||||
"company": "",
|
||||
"description": "",
|
||||
"keywords": "",
|
||||
"subject": "",
|
||||
"title": ""
|
||||
},
|
||||
"protected_structure": false,
|
||||
"sheets": [
|
||||
{
|
||||
"autofilter": null,
|
||||
"cells": {
|
||||
"bands": {
|
||||
"0": {
|
||||
"rows": {
|
||||
"0": {
|
||||
"0": {
|
||||
"formula": null,
|
||||
"style": 1,
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Item"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"formula": null,
|
||||
"style": 1,
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Qty"
|
||||
}
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"0": {
|
||||
"formula": null,
|
||||
"style": 0,
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Äpfel ✓"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"formula": null,
|
||||
"style": 2,
|
||||
"value": {
|
||||
"t": "Number",
|
||||
"v": 3.5
|
||||
}
|
||||
}
|
||||
},
|
||||
"2": {
|
||||
"0": {
|
||||
"formula": null,
|
||||
"style": 0,
|
||||
"value": {
|
||||
"t": "Text",
|
||||
"v": "Pears"
|
||||
}
|
||||
},
|
||||
"1": {
|
||||
"formula": null,
|
||||
"style": 2,
|
||||
"value": {
|
||||
"t": "Number",
|
||||
"v": 2.0
|
||||
}
|
||||
}
|
||||
},
|
||||
"3": {
|
||||
"1": {
|
||||
"formula": {
|
||||
"array": null,
|
||||
"text": "SUM(B2:B3)"
|
||||
},
|
||||
"style": 2,
|
||||
"value": {
|
||||
"t": "Number",
|
||||
"v": 5.5
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"len": 7
|
||||
},
|
||||
"charts": [],
|
||||
"cols": {},
|
||||
"comments": {},
|
||||
"cond_formats": [],
|
||||
"default_col_width": 64.0,
|
||||
"default_row_height": 20.0,
|
||||
"freeze": null,
|
||||
"hyperlinks": {},
|
||||
"images": [],
|
||||
"merges": [],
|
||||
"name": "Sheet1",
|
||||
"pivots": [],
|
||||
"print": {
|
||||
"center_h": false,
|
||||
"center_v": false,
|
||||
"col_breaks": [],
|
||||
"different_first": false,
|
||||
"different_odd_even": false,
|
||||
"even_footer": "",
|
||||
"even_header": "",
|
||||
"first_footer": "",
|
||||
"first_header": "",
|
||||
"fit_to": null,
|
||||
"footer": "",
|
||||
"gridlines": false,
|
||||
"header": "",
|
||||
"headings": false,
|
||||
"hf_align_with_margins": true,
|
||||
"hf_scale_with_doc": true,
|
||||
"margins": [
|
||||
0.699999988079071,
|
||||
0.699999988079071,
|
||||
0.75,
|
||||
0.75,
|
||||
0.30000001192092896,
|
||||
0.30000001192092896
|
||||
],
|
||||
"orientation": "Portrait",
|
||||
"page_order": "downThenOver",
|
||||
"paper": "Letter",
|
||||
"print_area": null,
|
||||
"row_breaks": [],
|
||||
"scale": 100,
|
||||
"title_cols": null,
|
||||
"title_rows": null
|
||||
},
|
||||
"protection": null,
|
||||
"right_to_left": false,
|
||||
"rows": {},
|
||||
"shapes": [],
|
||||
"show_formulas": false,
|
||||
"show_gridlines": true,
|
||||
"show_headings": true,
|
||||
"show_outline_symbols": true,
|
||||
"show_zeros": true,
|
||||
"slicers": [],
|
||||
"sparklines": [],
|
||||
"summary_below": true,
|
||||
"summary_right": true,
|
||||
"tab_color": null,
|
||||
"tables": [],
|
||||
"validations": [],
|
||||
"view": "normal",
|
||||
"view_active": {
|
||||
"col": 0,
|
||||
"row": 0
|
||||
},
|
||||
"view_top_left": {
|
||||
"col": 0,
|
||||
"row": 0
|
||||
},
|
||||
"visibility": "Visible",
|
||||
"zoom": 100
|
||||
}
|
||||
],
|
||||
"styles": {
|
||||
"styles": [
|
||||
{
|
||||
"align": {
|
||||
"h": "General",
|
||||
"indent": 0,
|
||||
"reading_order": null,
|
||||
"rotation": 0,
|
||||
"shrink": false,
|
||||
"v": "Bottom",
|
||||
"wrap": false
|
||||
},
|
||||
"borders": {
|
||||
"bottom": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"diag_down": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"diag_up": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"left": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"right": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"top": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
}
|
||||
},
|
||||
"dxf_stated": {
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"name": false,
|
||||
"protection": false,
|
||||
"scheme": null,
|
||||
"size": false,
|
||||
"strike": false,
|
||||
"underline": false
|
||||
},
|
||||
"fill": {
|
||||
"bg": "Auto",
|
||||
"fg": "Auto",
|
||||
"pattern": "None"
|
||||
},
|
||||
"font": {
|
||||
"bold": false,
|
||||
"charset": null,
|
||||
"color": "Auto",
|
||||
"family": null,
|
||||
"italic": false,
|
||||
"minor": true,
|
||||
"name": "Calibri",
|
||||
"size": 11.0,
|
||||
"strike": false,
|
||||
"underline": "None",
|
||||
"vert": "Baseline"
|
||||
},
|
||||
"num_fmt": "General",
|
||||
"protection": {
|
||||
"hidden": false,
|
||||
"locked": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"align": {
|
||||
"h": "General",
|
||||
"indent": 0,
|
||||
"reading_order": null,
|
||||
"rotation": 0,
|
||||
"shrink": false,
|
||||
"v": "Bottom",
|
||||
"wrap": false
|
||||
},
|
||||
"borders": {
|
||||
"bottom": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"diag_down": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"diag_up": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"left": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"right": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"top": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
}
|
||||
},
|
||||
"dxf_stated": {
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"name": false,
|
||||
"protection": false,
|
||||
"scheme": null,
|
||||
"size": false,
|
||||
"strike": false,
|
||||
"underline": false
|
||||
},
|
||||
"fill": {
|
||||
"bg": "Auto",
|
||||
"fg": "Auto",
|
||||
"pattern": "None"
|
||||
},
|
||||
"font": {
|
||||
"bold": true,
|
||||
"charset": null,
|
||||
"color": "Auto",
|
||||
"family": null,
|
||||
"italic": false,
|
||||
"minor": true,
|
||||
"name": "Calibri",
|
||||
"size": 11.0,
|
||||
"strike": false,
|
||||
"underline": "None",
|
||||
"vert": "Baseline"
|
||||
},
|
||||
"num_fmt": "General",
|
||||
"protection": {
|
||||
"hidden": false,
|
||||
"locked": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"align": {
|
||||
"h": "General",
|
||||
"indent": 0,
|
||||
"reading_order": null,
|
||||
"rotation": 0,
|
||||
"shrink": false,
|
||||
"v": "Bottom",
|
||||
"wrap": false
|
||||
},
|
||||
"borders": {
|
||||
"bottom": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"diag_down": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"diag_up": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"left": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"right": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
},
|
||||
"top": {
|
||||
"color": "Auto",
|
||||
"style": "None"
|
||||
}
|
||||
},
|
||||
"dxf_stated": {
|
||||
"bold": false,
|
||||
"italic": false,
|
||||
"name": false,
|
||||
"protection": false,
|
||||
"scheme": null,
|
||||
"size": false,
|
||||
"strike": false,
|
||||
"underline": false
|
||||
},
|
||||
"fill": {
|
||||
"bg": "Auto",
|
||||
"fg": "Auto",
|
||||
"pattern": "None"
|
||||
},
|
||||
"font": {
|
||||
"bold": false,
|
||||
"charset": null,
|
||||
"color": "Auto",
|
||||
"family": null,
|
||||
"italic": false,
|
||||
"minor": true,
|
||||
"name": "Calibri",
|
||||
"size": 11.0,
|
||||
"strike": false,
|
||||
"underline": "None",
|
||||
"vert": "Baseline"
|
||||
},
|
||||
"num_fmt": "0.00",
|
||||
"protection": {
|
||||
"hidden": false,
|
||||
"locked": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"theme": {
|
||||
"colors": [
|
||||
16777215,
|
||||
0,
|
||||
15263976,
|
||||
927809,
|
||||
1400962,
|
||||
15298866,
|
||||
1665828,
|
||||
1023701,
|
||||
10496915,
|
||||
5154606,
|
||||
4618374,
|
||||
9855101
|
||||
],
|
||||
"major_font": "Calibri",
|
||||
"major_font_cs": "",
|
||||
"major_font_ea": "",
|
||||
"major_font_scripts": [],
|
||||
"minor_font": "Calibri",
|
||||
"minor_font_cs": "",
|
||||
"minor_font_ea": "",
|
||||
"minor_font_scripts": [],
|
||||
"name": "Craft"
|
||||
},
|
||||
"vba_project": null
|
||||
}
|
||||
@@ -9,7 +9,10 @@ use crate::style::{Color, Style};
|
||||
mod pivot;
|
||||
mod print;
|
||||
|
||||
pub use pivot::{PivotCalcField, PivotDateGroup, PivotField, PivotFilter, PivotFunc, PivotLayout, PivotShowAs, PivotSort, PivotTable, PivotValue};
|
||||
pub use pivot::{
|
||||
PIVOT_INDEXER, PivotCalcField, PivotDataCell, PivotDateGroup, PivotField, PivotFilter, PivotFunc, PivotIndexer, PivotItemRef, PivotLayout,
|
||||
PivotLookup, PivotShowAs, PivotSort, PivotTable, PivotValue, pivot_key,
|
||||
};
|
||||
pub use print::{EditRange, HfPage, LineInfo, Orientation, PageOrder, PrintSettings, SheetProtection, password_hash};
|
||||
|
||||
// ---------------------------------------------------------------- tables
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use gridcraft_core::Value;
|
||||
|
||||
use super::{CellRef, RangeRef};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -131,6 +133,11 @@ pub struct PivotTable {
|
||||
pub last_range: Option<RangeRef>,
|
||||
/// Calculated fields, usable in the Values area by name.
|
||||
pub calculated_fields: Vec<PivotCalcField>,
|
||||
/// Where GETPIVOTDATA finds the report's value cells, as of the last refresh. Shared between
|
||||
/// workbook clones (so editing the pivot's sheet doesn't copy it), set on refresh and saved
|
||||
/// with the report, so a reopened unrefreshed pivot still reads the report it stored. Only a
|
||||
/// pivot loaded without one (XLSX) builds it on first use, checked against the stored report.
|
||||
pub data_index: PivotLookup,
|
||||
/// The Σ Values pseudo-field (it exists with two or more value fields) sits in Rows rather
|
||||
/// than Columns (Excel's "values on rows").
|
||||
pub values_on_rows: bool,
|
||||
@@ -149,6 +156,143 @@ pub struct PivotCalcField {
|
||||
pub formula: String,
|
||||
}
|
||||
|
||||
/// One value cell of a computed PivotTable report: the value field, the row and column items
|
||||
/// that locate it (fewer for subtotals, none for the grand total) and where the report shows it.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PivotDataCell {
|
||||
/// The value field's caption ("Sum of Sales").
|
||||
pub data_field: String,
|
||||
/// The value field's source column ("Sales").
|
||||
pub source_col: String,
|
||||
pub items: Vec<PivotItemRef>,
|
||||
/// Row and column of the cell, counted from the report's top-left cell.
|
||||
pub row: u32,
|
||||
pub col: u32,
|
||||
}
|
||||
|
||||
/// Builds a PivotTable's value cells from its source (`sheet` is the pivot's sheet). The engine
|
||||
/// sets it; the model can't compute reports.
|
||||
pub type PivotIndexer = fn(&crate::Workbook, usize, &PivotTable) -> Result<Vec<PivotDataCell>, String>;
|
||||
pub static PIVOT_INDEXER: std::sync::OnceLock<PivotIndexer> = std::sync::OnceLock::new();
|
||||
|
||||
fn norm(s: &str) -> String {
|
||||
s.trim().to_lowercase()
|
||||
}
|
||||
|
||||
/// One part of a lookup key: length-prefixed, so no label text can imitate a separator.
|
||||
fn key_part(out: &mut String, s: &str) {
|
||||
out.push_str(&s.len().to_string());
|
||||
out.push(':');
|
||||
out.push_str(s);
|
||||
}
|
||||
|
||||
/// The lookup key of a value field with field/item labels (names ignore case and outer blanks).
|
||||
/// Each item is `(field, label, is_bool)`: a Boolean item and a text item with the same label
|
||||
/// are different items.
|
||||
pub fn pivot_key(data_field: &str, items: &[(&str, &str, bool)]) -> String {
|
||||
let mut parts: Vec<String> = items
|
||||
.iter()
|
||||
.map(|(f, l, b)| {
|
||||
let mut p = String::new();
|
||||
key_part(&mut p, &norm(f));
|
||||
key_part(&mut p, &norm(l));
|
||||
p.push(if *b { 'b' } else { 't' });
|
||||
p
|
||||
})
|
||||
.collect();
|
||||
parts.sort_unstable();
|
||||
let mut key = String::new();
|
||||
key_part(&mut key, &norm(data_field));
|
||||
key.push_str(&parts.len().to_string());
|
||||
key.push('|');
|
||||
for p in parts {
|
||||
key.push_str(&p);
|
||||
}
|
||||
key
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct LookupInner {
|
||||
cells: std::sync::OnceLock<Vec<PivotDataCell>>,
|
||||
keys: std::sync::OnceLock<std::collections::HashMap<String, usize>>,
|
||||
}
|
||||
|
||||
/// A PivotTable's GETPIVOTDATA index. Clones share it, so `Workbook` clones per command stay
|
||||
/// cheap however large the report is. The cells are set on refresh or on first use; the hash of
|
||||
/// them is built on the first lookup.
|
||||
#[derive(Clone, Default)]
|
||||
pub struct PivotLookup(std::sync::Arc<LookupInner>);
|
||||
|
||||
impl PivotLookup {
|
||||
/// The value cells, if they were set.
|
||||
pub fn cells(&self) -> Option<&[PivotDataCell]> {
|
||||
self.0.cells.get().map(Vec::as_slice)
|
||||
}
|
||||
|
||||
/// Sets the value cells (the first set wins) and returns them.
|
||||
pub fn set_cells(&self, cells: Vec<PivotDataCell>) -> &[PivotDataCell] {
|
||||
self.0.cells.get_or_init(|| cells)
|
||||
}
|
||||
|
||||
/// The cell with this value field and exactly these items, by hash.
|
||||
pub fn find(&self, data_field: &str, items: &[(&str, &str, bool)]) -> Option<&PivotDataCell> {
|
||||
let cells = self.0.cells.get()?;
|
||||
let keys = self.0.keys.get_or_init(|| {
|
||||
let mut m = std::collections::HashMap::with_capacity(cells.len());
|
||||
for (i, c) in cells.iter().enumerate() {
|
||||
let items: Vec<(&str, &str, bool)> =
|
||||
c.items.iter().map(|it| (it.field.as_str(), it.label.as_str(), matches!(it.value, Value::Bool(_)))).collect();
|
||||
m.entry(pivot_key(&c.data_field, &items)).or_insert(i);
|
||||
m.entry(pivot_key(&c.source_col, &items)).or_insert(i);
|
||||
}
|
||||
m
|
||||
});
|
||||
keys.get(&pivot_key(data_field, items)).and_then(|i| cells.get(*i))
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for PivotLookup {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "PivotLookup({} cells)", self.cells().map_or(0, <[PivotDataCell]>::len))
|
||||
}
|
||||
}
|
||||
|
||||
/// Saved as the list of value cells (or nothing before the first refresh); the hash is rebuilt.
|
||||
/// An empty list is never saved: it is no index, and restoring one would lock the shared lookup
|
||||
/// against the lazy rebuild that a reopened workbook needs.
|
||||
impl Serialize for PivotLookup {
|
||||
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
|
||||
self.cells().filter(|cells| !cells.is_empty()).serialize(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for PivotLookup {
|
||||
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
|
||||
let l = PivotLookup::default();
|
||||
if let Some(cells) = Option::<Vec<PivotDataCell>>::deserialize(d)?
|
||||
&& !cells.is_empty()
|
||||
{
|
||||
l.set_cells(cells);
|
||||
}
|
||||
Ok(l)
|
||||
}
|
||||
}
|
||||
|
||||
/// The index is a cache, not part of a PivotTable's identity.
|
||||
impl PartialEq for PivotLookup {
|
||||
fn eq(&self, _: &Self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// A row or column field item: the field's source column, the item's label and its value.
|
||||
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
|
||||
pub struct PivotItemRef {
|
||||
pub field: String,
|
||||
pub label: String,
|
||||
pub value: Value,
|
||||
}
|
||||
|
||||
impl Default for PivotTable {
|
||||
fn default() -> Self {
|
||||
PivotTable {
|
||||
@@ -170,8 +314,65 @@ impl Default for PivotTable {
|
||||
show_headers: true,
|
||||
last_range: None,
|
||||
calculated_fields: vec![],
|
||||
data_index: PivotLookup::default(),
|
||||
values_on_rows: false,
|
||||
values_position: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod pivot_lookup_tests {
|
||||
use super::*;
|
||||
|
||||
fn cell(field: &str, label: &str, value: Value, row: u32) -> PivotDataCell {
|
||||
PivotDataCell {
|
||||
data_field: "Sum of Sales".into(),
|
||||
source_col: "Sales".into(),
|
||||
items: vec![PivotItemRef { field: field.into(), label: label.into(), value }],
|
||||
row,
|
||||
col: 1,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn labels_with_separator_characters_do_not_collide() {
|
||||
let l = PivotLookup::default();
|
||||
// Two different (field, label) pairs that a separator-joined key would make identical.
|
||||
l.set_cells(vec![cell("A\u{2}B", "C", Value::Text("C".into()), 1), cell("A", "B\u{2}C", Value::Text("B\u{2}C".into()), 2)]);
|
||||
assert_eq!(l.find("Sales", &[("A\u{2}B", "C", false)]).unwrap().row, 1);
|
||||
assert_eq!(l.find("Sales", &[("A", "B\u{2}C", false)]).unwrap().row, 2);
|
||||
// A label carrying the old pair separator cannot stand for two items.
|
||||
assert!(l.find("Sales", &[("A", "B", false), ("C", "D", false)]).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn boolean_and_text_items_with_one_label_are_different_items() {
|
||||
let l = PivotLookup::default();
|
||||
l.set_cells(vec![cell("Flag", "TRUE", Value::Text("TRUE".into()), 1), cell("Flag", "TRUE", Value::Bool(true), 2)]);
|
||||
assert_eq!(l.find("Sales", &[("Flag", "TRUE", true)]).unwrap().row, 2);
|
||||
assert_eq!(l.find("Sales", &[("Flag", "TRUE", false)]).unwrap().row, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index_round_trips_through_serde() {
|
||||
let l = PivotLookup::default();
|
||||
l.set_cells(vec![cell("Region", "East", Value::Text("East".into()), 1)]);
|
||||
let back: PivotLookup = serde_json::from_str(&serde_json::to_string(&l).unwrap()).unwrap();
|
||||
assert_eq!(back.find("Sales", &[("Region", "East", false)]).unwrap().row, 1);
|
||||
let none: PivotLookup = serde_json::from_str(&serde_json::to_string(&PivotLookup::default()).unwrap()).unwrap();
|
||||
assert!(none.cells().is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_lookup_is_saved_as_no_index() {
|
||||
// An empty cell list is no index, so it must not be saved as an empty one: restoring an
|
||||
// empty index counts as an initialized lookup, which blocks the lazy rebuild.
|
||||
let l = PivotLookup::default();
|
||||
l.set_cells(vec![]);
|
||||
let saved = serde_json::to_string(&l).unwrap();
|
||||
assert_eq!(saved, "null", "an empty lookup saves no index: {saved}");
|
||||
let back: PivotLookup = serde_json::from_str("[]").unwrap();
|
||||
assert!(back.cells().is_none(), "an empty saved list restores no index");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ readme = "README.md"
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-pdf.workspace = true
|
||||
craft-stream-codecs.workspace = true
|
||||
harfrust = "=0.12.0"
|
||||
skrifa = { workspace = true }
|
||||
|
||||
@@ -10,7 +10,7 @@ use skrifa::{
|
||||
};
|
||||
use unicode_bidi::BidiInfo;
|
||||
|
||||
use crate::{CID_FONT, Error, Font, TextDirection, dict_obj, n, needs_cid, pdf_string, pdf_utf16_string, stream_obj};
|
||||
use crate::{CID_FONT, Error, Font, TextDirection, n, needs_cid, pdf_string, pdf_utf16_string};
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/arabic_fonts.rs"));
|
||||
|
||||
@@ -490,7 +490,7 @@ impl Subset {
|
||||
}
|
||||
|
||||
/// Writes the subset fonts into `out` and returns their page resource entries.
|
||||
pub(crate) fn write_objects(&self, next: &mut u32, out: &mut Vec<u8>, offsets: &mut Vec<usize>) -> String {
|
||||
pub(crate) fn write_objects(&self, next: &mut u32, out: &mut craft_pdf::classic::Writer) -> Result<String, Error> {
|
||||
let mut resources = String::new();
|
||||
for (batch, glyphs) in self.glyphs.chunks(255).enumerate() {
|
||||
let id = *next;
|
||||
@@ -507,7 +507,7 @@ impl Subset {
|
||||
let _ = write!(names, "/g{code} ");
|
||||
let _ = write!(widths, "{} ", n(glyph.width));
|
||||
let body = glyph_procedure(glyph);
|
||||
stream_obj(out, offsets, *next, "", body.as_bytes());
|
||||
out.stream(*next, "", body.as_bytes())?;
|
||||
*next += 1;
|
||||
bounds[0] = bounds[0].min(glyph.bounds[0]);
|
||||
bounds[1] = bounds[1].min(glyph.bounds[1]);
|
||||
@@ -526,11 +526,8 @@ impl Subset {
|
||||
cmap.push_str("endbfchar\n");
|
||||
}
|
||||
cmap.push_str("endcmap\nCMapName currentdict /CMap defineresource pop\nend\nend\n");
|
||||
stream_obj(out, offsets, cmap_id, "", cmap.as_bytes());
|
||||
dict_obj(
|
||||
out,
|
||||
offsets,
|
||||
id,
|
||||
out.stream(cmap_id, "", cmap.as_bytes())?;
|
||||
out.object(id,
|
||||
&format!(
|
||||
"<< /Type /Font /Subtype /Type3 /Name /GridCraftArabic /FontBBox [{} {} {} {}] /FontMatrix [0.001 0 0 0.001 0 0] /CharProcs << {procs}>> /Encoding << /Type /Encoding /Differences [1 {names}] >> /FirstChar 1 /LastChar {} /Widths [{widths}] /Resources << >> /ToUnicode {cmap_id} 0 R >>",
|
||||
n(bounds[0]),
|
||||
@@ -539,10 +536,10 @@ impl Subset {
|
||||
n(bounds[3]),
|
||||
glyphs.len()
|
||||
),
|
||||
);
|
||||
)?;
|
||||
let _ = write!(resources, "/A{} {id} 0 R ", batch + 1);
|
||||
}
|
||||
resources
|
||||
Ok(resources)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+29
-88
@@ -1,4 +1,4 @@
|
||||
//! A tiny, self-contained PDF 1.7 writer for GridCraft's print and PDF export.
|
||||
//! PDF 1.7 drawing for GridCraft print/export, with shared object and xref framing.
|
||||
//!
|
||||
//! - The 14 standard fonts (no embedding) with WinAnsiEncoding, plus approximate width tables
|
||||
//! ([`text_width`]) so callers can measure, align and wrap text. Characters outside
|
||||
@@ -52,7 +52,7 @@ impl TextDirection {
|
||||
}
|
||||
}
|
||||
|
||||
/// A PDF export could not preserve the requested text.
|
||||
/// A PDF export could not preserve the requested text or serialize its object envelope.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Error(String);
|
||||
|
||||
@@ -63,6 +63,12 @@ impl std::fmt::Display for Error {
|
||||
}
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
impl From<craft_pdf::classic::Error> for Error {
|
||||
fn from(error: craft_pdf::classic::Error) -> Self {
|
||||
Self(error.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::fmt::Write as _;
|
||||
@@ -1001,49 +1007,6 @@ fn pdf_text_string(text: &str) -> String {
|
||||
s
|
||||
}
|
||||
|
||||
/// Starts object `id` at the current end of `out` and records its offset for the xref table.
|
||||
fn begin_obj(out: &mut Vec<u8>, offsets: &mut Vec<usize>, id: u32) {
|
||||
let i = id as usize;
|
||||
if offsets.len() <= i {
|
||||
offsets.resize(i + 1, 0);
|
||||
}
|
||||
if let Some(slot) = offsets.get_mut(i) {
|
||||
*slot = out.len();
|
||||
}
|
||||
let _ = writeln!(Utf8(out), "{id} 0 obj");
|
||||
}
|
||||
|
||||
/// Writes `id 0 obj <body> endobj`.
|
||||
fn dict_obj(out: &mut Vec<u8>, offsets: &mut Vec<usize>, id: u32, body: &str) {
|
||||
begin_obj(out, offsets, id);
|
||||
out.extend_from_slice(body.as_bytes());
|
||||
out.extend_from_slice(b"\nendobj\n");
|
||||
}
|
||||
|
||||
/// Writes a stream object: `dict` (the dictionary entries without `<<`, `>>` and `/Length`, may be
|
||||
/// empty) and `data` as the stream body.
|
||||
fn stream_obj(out: &mut Vec<u8>, offsets: &mut Vec<usize>, id: u32, dict: &str, data: &[u8]) {
|
||||
begin_obj(out, offsets, id);
|
||||
out.extend_from_slice(b"<<");
|
||||
if !dict.is_empty() {
|
||||
out.push(b' ');
|
||||
out.extend_from_slice(dict.as_bytes());
|
||||
}
|
||||
let _ = write!(Utf8(out), " /Length {} >>\nstream\n", data.len());
|
||||
out.extend_from_slice(data);
|
||||
out.extend_from_slice(b"\nendstream\nendobj\n");
|
||||
}
|
||||
|
||||
/// Lets `write!` append text to a byte buffer.
|
||||
struct Utf8<'a>(&'a mut Vec<u8>);
|
||||
|
||||
impl std::fmt::Write for Utf8<'_> {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
self.0.extend_from_slice(s.as_bytes());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PdfDoc {
|
||||
pub fn new() -> PdfDoc {
|
||||
PdfDoc::default()
|
||||
@@ -1097,7 +1060,8 @@ impl PdfDoc {
|
||||
/// numbered during writing (fonts, then per page its new images, content stream and page
|
||||
/// dictionary), with the catalog, page tree and info dictionary last.
|
||||
///
|
||||
/// Returns an error if the Arabic font is unusable or Arabic text exceeds a size limit.
|
||||
/// Returns an error if the Arabic font is unusable, text exceeds a size limit, or the
|
||||
/// shared envelope writer refuses object counts, offsets or an allocation.
|
||||
pub fn finish(mut self) -> Result<Vec<u8>, Error> {
|
||||
if let Some(error) = self.pages.iter().find_map(|page| page.error.clone()) {
|
||||
return Err(error);
|
||||
@@ -1131,9 +1095,7 @@ impl PdfDoc {
|
||||
let contents: Vec<String> = self.pages.iter_mut().map(|p| std::mem::take(&mut p.content)).collect();
|
||||
let page_links: Vec<Vec<LinkAnnotation>> = self.pages.iter_mut().map(|p| std::mem::take(&mut p.links)).collect();
|
||||
let reserve = contents.iter().fold(4096usize, |acc, c| acc.saturating_add(c.len()).saturating_add(1024));
|
||||
let mut out: Vec<u8> = Vec::with_capacity(reserve);
|
||||
out.extend_from_slice(b"%PDF-1.7\n%\xE2\xE3\xCF\xD3\n");
|
||||
let mut offsets: Vec<usize> = vec![0; 4];
|
||||
let mut out = craft_pdf::classic::Writer::with_capacity(reserve)?;
|
||||
let mut kids = Vec::new();
|
||||
let mut annotations = Vec::new();
|
||||
let page_count = self.pages.len();
|
||||
@@ -1143,42 +1105,34 @@ impl PdfDoc {
|
||||
let _ = write!(font_dict, "/F{} {} 0 R ", i + 1, id);
|
||||
if i == CID_FONT {
|
||||
let (cid_id, desc_id) = (id + 1, id + 2);
|
||||
dict_obj(
|
||||
&mut out,
|
||||
&mut offsets,
|
||||
out.object(
|
||||
*id,
|
||||
&format!(
|
||||
"<< /Type /Font /Subtype /Type0 /BaseFont /{CID_BASE_FONT} /Encoding /UniGB-UTF16-H /DescendantFonts [{cid_id} 0 R] >>"
|
||||
),
|
||||
);
|
||||
dict_obj(
|
||||
&mut out,
|
||||
&mut offsets,
|
||||
cid_id,
|
||||
)?;
|
||||
out.object(cid_id,
|
||||
&format!(
|
||||
"<< /Type /Font /Subtype /CIDFontType0 /BaseFont /{CID_BASE_FONT} /CIDSystemInfo << /Registry (Adobe) /Ordering (GB1) /Supplement 4 >> /FontDescriptor {desc_id} 0 R /DW {CID_WIDTH} >>"
|
||||
),
|
||||
);
|
||||
dict_obj(
|
||||
&mut out,
|
||||
&mut offsets,
|
||||
desc_id,
|
||||
)?;
|
||||
out.object(desc_id,
|
||||
&format!(
|
||||
"<< /Type /FontDescriptor /FontName /{CID_BASE_FONT} /Flags 6 /FontBBox [-25 -254 1000 880] /ItalicAngle 0 /Ascent 880 /Descent -120 /CapHeight 880 /StemV 93 >>"
|
||||
),
|
||||
);
|
||||
)?;
|
||||
continue;
|
||||
}
|
||||
let name = Font::ALL.get(i).copied().unwrap_or_default().base_name();
|
||||
let enc = if name.starts_with("Symbol") { "" } else { " /Encoding /WinAnsiEncoding" };
|
||||
dict_obj(&mut out, &mut offsets, *id, &format!("<< /Type /Font /Subtype /Type1 /BaseFont /{name}{enc} >>"));
|
||||
out.object(*id, &format!("<< /Type /Font /Subtype /Type1 /BaseFont /{name}{enc} >>"))?;
|
||||
}
|
||||
}
|
||||
// Images already written, by content hash: (page, image, object id). A hash match is
|
||||
// confirmed by comparing the pixels before an object is shared.
|
||||
let mut written: HashMap<u64, Vec<(usize, usize, u32)>> = HashMap::new();
|
||||
for (pi, ((page, content), links)) in self.pages.iter().zip(contents).zip(page_links).enumerate() {
|
||||
let arabic_fonts = page.arabic.write_objects(&mut next, &mut out, &mut offsets);
|
||||
let arabic_fonts = page.arabic.write_objects(&mut next, &mut out)?;
|
||||
let page_fonts = format!("{font_dict}{arabic_fonts}");
|
||||
let mut xobjects = String::new();
|
||||
for (k, img) in page.images.iter().enumerate() {
|
||||
@@ -1204,13 +1158,13 @@ impl PdfDoc {
|
||||
let _ = write!(dict, " /SMask {id} 0 R");
|
||||
}
|
||||
dict.push_str(" /Filter /RunLengthDecode");
|
||||
stream_obj(&mut out, &mut offsets, img_id, &dict, &run_length(&img.rgb));
|
||||
out.stream(img_id, &dict, &run_length(&img.rgb))?;
|
||||
if let (Some(id), Some(a)) = (smask_id, &img.alpha) {
|
||||
let dict = format!(
|
||||
"/Type /XObject /Subtype /Image /Width {} /Height {} /ColorSpace /DeviceGray /BitsPerComponent 8 /Filter /RunLengthDecode",
|
||||
img.width, img.height
|
||||
);
|
||||
stream_obj(&mut out, &mut offsets, id, &dict, &run_length(a));
|
||||
out.stream(id, &dict, &run_length(a))?;
|
||||
}
|
||||
written.entry(img.hash).or_default().push((pi, k, img_id));
|
||||
img_id
|
||||
@@ -1221,7 +1175,7 @@ impl PdfDoc {
|
||||
let content_id = next;
|
||||
let page_id = next + 1;
|
||||
next += 2;
|
||||
stream_obj(&mut out, &mut offsets, content_id, "", content.as_bytes());
|
||||
out.stream(content_id, "", content.as_bytes())?;
|
||||
drop(content);
|
||||
let xo = if xobjects.is_empty() { String::new() } else { format!(" /XObject << {xobjects}>>") };
|
||||
let mut link_refs = String::new();
|
||||
@@ -1235,9 +1189,7 @@ impl PdfDoc {
|
||||
annotations.push((id, link));
|
||||
}
|
||||
let annots = if link_refs.is_empty() { String::new() } else { format!(" /Annots [{link_refs}]") };
|
||||
dict_obj(
|
||||
&mut out,
|
||||
&mut offsets,
|
||||
out.object(
|
||||
page_id,
|
||||
&format!(
|
||||
"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 {} {}] /Resources << /Font << {}>>{} >> /Contents {} 0 R{} >>",
|
||||
@@ -1248,7 +1200,7 @@ impl PdfDoc {
|
||||
content_id,
|
||||
annots
|
||||
),
|
||||
);
|
||||
)?;
|
||||
kids.push(page_id);
|
||||
}
|
||||
for (id, link) in annotations {
|
||||
@@ -1261,16 +1213,11 @@ impl PdfDoc {
|
||||
format!("/Dest [{page_id} 0 R /XYZ {} {} null]", n(x), n(height - y))
|
||||
}
|
||||
};
|
||||
dict_obj(
|
||||
&mut out,
|
||||
&mut offsets,
|
||||
id,
|
||||
&format!("<< /Type /Annot /Subtype /Link /Rect [{} {} {} {}] /Border [0 0 0] {action} >>", n(x0), n(y0), n(x1), n(y1)),
|
||||
);
|
||||
out.object(id, &format!("<< /Type /Annot /Subtype /Link /Rect [{} {} {} {}] /Border [0 0 0] {action} >>", n(x0), n(y0), n(x1), n(y1)))?;
|
||||
}
|
||||
dict_obj(&mut out, &mut offsets, 1, "<< /Type /Catalog /Pages 2 0 R >>");
|
||||
out.object(1, "<< /Type /Catalog /Pages 2 0 R >>")?;
|
||||
let kids_s: Vec<String> = kids.iter().map(|k| format!("{k} 0 R")).collect();
|
||||
dict_obj(&mut out, &mut offsets, 2, &format!("<< /Type /Pages /Kids [{}] /Count {} >>", kids_s.join(" "), kids.len()));
|
||||
out.object(2, &format!("<< /Type /Pages /Kids [{}] /Count {} >>", kids_s.join(" "), kids.len()))?;
|
||||
let creator = if self.info.creator.is_empty() { "GridCraft" } else { &self.info.creator };
|
||||
let mut info = format!("<< /Producer {} /Creator {}", pdf_text_string("GridCraft PDF"), pdf_text_string(creator));
|
||||
if !self.info.title.is_empty() {
|
||||
@@ -1280,15 +1227,9 @@ impl PdfDoc {
|
||||
let _ = write!(info, " /Author {}", pdf_text_string(&self.info.author));
|
||||
}
|
||||
info.push_str(" >>");
|
||||
dict_obj(&mut out, &mut offsets, 3, &info);
|
||||
out.object(3, &info)?;
|
||||
|
||||
let xref = out.len();
|
||||
let _ = write!(Utf8(&mut out), "xref\n0 {}\n0000000000 65535 f \n", next);
|
||||
for off in offsets.iter().skip(1) {
|
||||
let _ = writeln!(Utf8(&mut out), "{off:010} 00000 n ");
|
||||
}
|
||||
let _ = write!(Utf8(&mut out), "trailer\n<< /Size {} /Root 1 0 R /Info 3 0 R >>\nstartxref\n{}\n%%EOF\n", next, xref);
|
||||
Ok(out)
|
||||
out.finish(1, Some(3)).map_err(Error::from)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1136,7 +1136,10 @@ fn explicit_rtl_standard_text_reorders_without_an_arabic_font() {
|
||||
let page = doc.add_page(300.0, 100.0);
|
||||
page.text_with_direction(Point::new(10.0, 30.0), 12.0, Font::Helvetica, [0, 0, 0], source, TextDirection::RightToLeft);
|
||||
assert!(page.content.contains("(! ABC) Tj"), "{}", page.content);
|
||||
assert!(page.arabic.write_objects(&mut 4, &mut Vec::new(), &mut Vec::new()).is_empty());
|
||||
let mut objects = craft_pdf::classic::Writer::with_capacity(0).unwrap();
|
||||
let mut next = 4;
|
||||
assert!(page.arabic.write_objects(&mut next, &mut objects).unwrap().is_empty());
|
||||
assert_eq!(next, 4, "Latin-only RTL text must not allocate Arabic font objects");
|
||||
assert_eq!(text_width_with_direction(Font::Helvetica, 12.0, source, TextDirection::RightToLeft), text_width(Font::Helvetica, 12.0, source));
|
||||
let pdf = doc.finish().unwrap();
|
||||
assert_eq!(utf16_entry(&pdf, "/ActualText").unwrap(), source);
|
||||
|
||||
@@ -23,6 +23,7 @@ craft-csv = { workspace = true }
|
||||
craft-offcrypto = { workspace = true }
|
||||
craft-opc = { workspace = true }
|
||||
craft-xls = { workspace = true }
|
||||
craft-xml = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
quick-xml = { workspace = true }
|
||||
zip = { workspace = true }
|
||||
|
||||
@@ -116,6 +116,7 @@ fn workbook() -> Workbook {
|
||||
show_headers: false,
|
||||
last_range: Some(rr("A2:H12")),
|
||||
calculated_fields: vec![],
|
||||
data_index: Default::default(),
|
||||
values_on_rows: false,
|
||||
values_position: None,
|
||||
};
|
||||
@@ -176,6 +177,7 @@ fn workbook() -> Workbook {
|
||||
show_headers: true,
|
||||
last_range: Some(rr("K2:Z30")),
|
||||
calculated_fields: vec![],
|
||||
data_index: Default::default(),
|
||||
values_on_rows: false,
|
||||
values_position: None,
|
||||
};
|
||||
|
||||
+21
-48
@@ -359,31 +359,11 @@ pub fn parse_streaming(xml: &[u8], split: &[&str], cb: &mut dyn FnMut(El) -> Res
|
||||
|
||||
// ---------------------------------------------------------------- writing helpers
|
||||
|
||||
/// Escapes text content.
|
||||
pub fn esc(s: &str) -> String {
|
||||
let mut o = String::with_capacity(s.len());
|
||||
push_esc(&mut o, s);
|
||||
o
|
||||
}
|
||||
|
||||
/// Appends [`esc`]`(s)` to `o`.
|
||||
pub fn push_esc(o: &mut String, s: &str) {
|
||||
if s.bytes().all(|b| matches!(b, b'\t' | b'\n' | 0x20..=0x7E) && !matches!(b, b'&' | b'<' | b'>')) {
|
||||
o.push_str(s);
|
||||
return;
|
||||
}
|
||||
o.reserve(s.len());
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'&' => o.push_str("&"),
|
||||
'<' => o.push_str("<"),
|
||||
'>' => o.push_str(">"),
|
||||
'\r' => o.push_str(" "),
|
||||
c if is_xml_char(c) => o.push(c),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
// XML 1.0 byte escaping is shared; spreadsheet string and phonetic policy stays here.
|
||||
use craft_xml::is_xml_char;
|
||||
#[cfg(test)]
|
||||
use craft_xml::push_esc;
|
||||
pub use craft_xml::{esc, esc_attr};
|
||||
|
||||
/// Appends `n` in decimal.
|
||||
pub fn push_u64(o: &mut String, mut n: u64) {
|
||||
@@ -422,29 +402,6 @@ pub fn push_a1(o: &mut String, c: gridcraft_core::CellRef) {
|
||||
push_u64(o, u64::from(c.row) + 1);
|
||||
}
|
||||
|
||||
/// Escapes an attribute value (double-quoted).
|
||||
pub fn esc_attr(s: &str) -> String {
|
||||
let mut o = String::with_capacity(s.len());
|
||||
for c in s.chars() {
|
||||
match c {
|
||||
'&' => o.push_str("&"),
|
||||
'<' => o.push_str("<"),
|
||||
'>' => o.push_str(">"),
|
||||
'"' => o.push_str("""),
|
||||
'\n' => o.push_str(" "),
|
||||
'\r' => o.push_str(" "),
|
||||
'\t' => o.push_str("	"),
|
||||
c if is_xml_char(c) => o.push(c),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
o
|
||||
}
|
||||
|
||||
fn is_xml_char(c: char) -> bool {
|
||||
matches!(c, '\t' | '\n' | '\r' | '\u{20}'..='\u{D7FF}' | '\u{E000}'..='\u{FFFD}' | '\u{10000}'..='\u{10FFFF}')
|
||||
}
|
||||
|
||||
/// ST_Xstring encoding for cell text: characters XML can't carry and carriage returns become
|
||||
/// `_xHHHH_`, and literal `_xHHHH_` sequences are protected with `_x005F_`. The result still needs
|
||||
/// [`esc`].
|
||||
@@ -805,3 +762,19 @@ mod tests {
|
||||
assert_eq!("1.5E20".parse::<f64>().unwrap(), 1.5e20);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod shared_escape_parity {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn xml_content_and_attributes_preserve_grid_bytes() {
|
||||
let value = "&<>\"'\t\n\r\0\u{1f}\u{fffe}\u{ffff}é😀";
|
||||
assert_eq!(esc(value), "&<>\"'\t\n é😀");
|
||||
assert_eq!(esc_attr(value), "&<>"'	 é😀");
|
||||
let mut appended = "prefix:".to_owned();
|
||||
push_esc(&mut appended, value);
|
||||
assert_eq!(appended, format!("prefix:{}", esc(value)));
|
||||
assert_eq!(esc("plain ASCII\t\n"), "plain ASCII\t\n");
|
||||
assert_eq!(decode_xstring(&encode_xstring("_x000D_\r\0😀")), "_x000D_\r\0😀");
|
||||
}
|
||||
}
|
||||
|
||||
+10
-13
@@ -12,13 +12,9 @@ Excel's worksheet functions, category by category, against GridCraft's function
|
||||
them), plus 14 text functions the page lists under combined entries (FIND/FINDB, LEFT/LEFTB,
|
||||
LEN/LENB, MID/MIDB, REPLACE/REPLACEB, RIGHT/RIGHTB, SEARCH/SEARCHB), BETA.INV, and COPILOT and
|
||||
PY (Microsoft 365 functions not on that page when fetched).
|
||||
- **Ours (505):** every function spec in `crates/functions/src/*.rs` (`f!("NAME", …)`) plus the
|
||||
- **Ours (503):** every function spec in `crates/functions/src/*.rs` (`f!("NAME", …)`) plus the
|
||||
- **Ours (502):** every function spec in `crates/functions/src/*.rs` (`f!("NAME", …)`) plus the
|
||||
- **Ours (502):** every function spec in `crates/functions/src/*.rs` (`f!("NAME", …)`) plus the
|
||||
- **Ours (505):** every function spec in `crates/functions/src/*.rs` (`f!("NAME", …)`) plus the
|
||||
- **Ours (514):** every function spec in `crates/functions/src/*.rs` (`f!("NAME", …)`) plus the
|
||||
evaluator's special forms in `crates/calc/src/eval.rs` (`SPECIAL_FUNCTIONS`: IF, IFS, CHOOSE,
|
||||
OFFSET, INDIRECT, INDEX, SUBTOTAL, AGGREGATE, TEXT, LET, LAMBDA, MAP, REDUCE, SCAN, BYROW, BYCOL,
|
||||
OFFSET, INDIRECT, INDEX, GETPIVOTDATA, SUBTOTAL, AGGREGATE, TEXT, LET, LAMBDA, MAP, REDUCE, SCAN, BYROW, BYCOL,
|
||||
MAKEARRAY…), excluding the test-only `ADD2`. Every one is an Excel name.
|
||||
- **Not on Microsoft's list:** USDOLLAR and ECMA.CEILING, legacy functions Excel still evaluates (like DOLLAR),
|
||||
are in our library as Compatibility functions for files that use them. They are not counted above.
|
||||
@@ -29,7 +25,7 @@ Excel's worksheet functions, category by category, against GridCraft's function
|
||||
|
||||
## Coverage
|
||||
|
||||
**Measured: 513 / 523 by name (98.1%); 504 / 523 working (96.4%).**
|
||||
**Measured: 514 / 523 by name (98.3%); 505 / 523 working (96.6%).**
|
||||
|
||||
| Category | Excel | Ours | Working | % working | Missing |
|
||||
|---|---|---|---|---|---|
|
||||
@@ -38,7 +34,7 @@ Excel's worksheet functions, category by category, against GridCraft's function
|
||||
| Financial | 55 | 55 | 55 | 100% | — |
|
||||
| Engineering | 54 | 54 | 54 | 100% | — |
|
||||
| Text | 50 | 48 | 48 | 96% | DETECTLANGUAGE, TRANSLATE |
|
||||
| Lookup and reference | 40 | 36 | 36 | 90% | GETPIVOTDATA, IMAGE, RTD, TRIMRANGE |
|
||||
| Lookup and reference | 40 | 38 | 38 | 95% | IMAGE, RTD |
|
||||
| Compatibility | 40 | 40 | 40 | 100% | — |
|
||||
| Date and time | 25 | 25 | 25 | 100% | — |
|
||||
| Information | 22 | 21 | 21 | 95% | STOCKHISTORY |
|
||||
@@ -48,10 +44,10 @@ Excel's worksheet functions, category by category, against GridCraft's function
|
||||
| Web | 3 | 3 | 1 | 33% | (WEBSERVICE, FILTERXML are stubs; ENCODEURL works) |
|
||||
| Add-in and Automation | 3 | 1 | 1 | 33% | CALL, REGISTER.ID |
|
||||
| AI and Python | 2 | 0 | 0 | 0% | COPILOT, PY |
|
||||
| **Total** | **523** | **505** | **496** | **94.8%** | 18 missing, 9 stubs |
|
||||
| **Total** | **523** | **514** | **505** | **96.6%** | 9 missing, 9 stubs |
|
||||
|
||||
By the Excel version that introduced them (working / total): before 2010 346 / 360, 2010
|
||||
56 / 56, 2013 49 / 51, 2016 1 / 5, 2019 6 / 6, 2021 11 / 11, 2024 22 / 23, Microsoft 365 5 / 11.
|
||||
By the Excel version that introduced them (working / total): before 2010 349 / 360, 2010
|
||||
56 / 56, 2013 49 / 51, 2016 5 / 5, 2019 6 / 6, 2021 11 / 11, 2024 22 / 23, Microsoft 365 7 / 11.
|
||||
Dynamic-array and LAMBDA-era functions (FILTER, SORT, UNIQUE, XLOOKUP, VSTACK, TAKE, GROUPBY,
|
||||
PIVOTBY, REGEXTEST…) are all present.
|
||||
|
||||
@@ -66,7 +62,7 @@ This improves series preparation; it does not change the model-fitting or season
|
||||
|---|---|---|---|
|
||||
| FORECAST.ETS family (4) | yes | 4–6 h | AAA exponential smoothing with seasonality detection; needed for Forecast Sheet too |
|
||||
| ODDFPRICE, ODDFYIELD, ODDLPRICE, ODDLYIELD | yes | 2–4 h | Odd first/last period bond maths |
|
||||
| GETPIVOTDATA | yes | 2–3 h | Needs the pivot engine's result cache; also the "Generate GetPivotData" option |
|
||||
| Generate GetPivotData | yes | 1–2 h | GETPIVOTDATA works; clicking a PivotTable value while typing a formula doesn't insert it yet |
|
||||
| IMAGE | yes | 3–5 h | Pictures in cells (see PR #105); fetching URLs needs a privacy decision |
|
||||
| CUBE* (7), WEBSERVICE, FILTERXML | partly | 4–8 h | FILTERXML can work offline; CUBE needs an OLAP/data-model source |
|
||||
| TRANSLATE, DETECTLANGUAGE, STOCKHISTORY, COPILOT, PY | no (cloud) | — | Microsoft cloud services; open equivalents only by owner decision |
|
||||
@@ -128,7 +124,7 @@ inputs, so large finite middle values do not become `#NUM!` merely because their
|
||||
Sorting, argument coercion and error propagation are unchanged; this is a numerical correction
|
||||
under the documented median rule, not an extreme-value comparison against desktop Excel.
|
||||
|
||||
Work to close (16–26 h in total): the in-scope missing functions (10–16 h with the table above),
|
||||
Work to close (15–25 h in total): the in-scope missing functions (10–16 h with the table above),
|
||||
an oracle corpus of Excel-computed results per function (owner runs Excel on generated
|
||||
workbooks; results checked in as data, not Excel files) and fixing what it finds (6–10 h).
|
||||
|
||||
@@ -183,6 +179,7 @@ Positive fractional inputs still truncate, and signed zero remains valid. Covere
|
||||
| 2026-10-14 | minor | Bounded references up to 1,048,576 cells (`D3:AZ400`) keep their full shape instead of stopping at the used range, so `SUMPRODUCT(D3:AZ400*B3:B400,(A3:A400=x)*(D1:AZ1=y))` broadcasts like Excel and `ROWS`, `COUNTBLANK` and `--(r="")` count the blanks; references that run to the edge of the sheet (`A:A`) still stop at the used range (#1010) |
|
||||
| 2026-10-13 | minor | Legacy formulas from files (no dynamic-array metadata) evaluate with implicit intersection: cells differing from Excel's cached values 68,964 → 49,866 across 4,224 test-corpus workbooks (none gets more) |
|
||||
| 2026-10-13 | minor | Clear reports changed stored cells sparsely, including those beyond the first million coordinates; dependent formulas and removed spills update, while clearing empty merges still unblocks spills (#1032) |
|
||||
| 2026-10-12 | minor | GETPIVOTDATA added: 514 / 523 by name, 505 working |
|
||||
| 2026-10-12 | minor | USDOLLAR added as a Compatibility function (not on Microsoft's list, so the counts don't change); MIRR with no positive flow is -1, COUNTIF's bare `"<="` / `">="` skip empty strings, INDIRECT with `a1` = FALSE gives `#REF!` for A1-style text (#738) |
|
||||
| 2026-10-11 | minor | TEXT / number formats fixed against Excel-cached results: fraction literals and zero fractions, `0` denominators zero padded, `?` pads the thousands separator, booleans use the text section (226 mismatches → 0 in 352 TEXT cells) |
|
||||
| 2026-10-11 | minor | Iterative calculation: circular references iterate up to Maximum Iterations / Maximum Change when enabled |
|
||||
|
||||
+4
-6
@@ -91,8 +91,8 @@ No alpha blockers: every core workflow passes the [alpha gate](roadmap.md#alpha-
|
||||
|
||||
### 8. PivotTables: no slicers, calculated items, PivotCharts; unverified in Excel (F)
|
||||
- **Evidence:** `parity-checklist.md` missing `insert.slicer`, `insert.timeline`,
|
||||
`insert.pivotChart`, `table.insertSlicer`; calculated items and GETPIVOTDATA missing (calculated fields
|
||||
and values on rows done). Show Details (double-click a value, subtotal or grand total cell) lists
|
||||
`insert.pivotChart`, `table.insertSlicer`; calculated items and Generate GetPivotData missing (calculated fields,
|
||||
values on rows and GETPIVOTDATA done). Show Details (double-click a value, subtotal or grand total cell) lists
|
||||
its source records on a new sheet. The "Enable show details" option (`pivot.options`
|
||||
`enableShowDetails`, saved as `enableDrill`) turns it off; it has no PivotTable Options dialog
|
||||
yet (command only).
|
||||
@@ -142,10 +142,7 @@ No alpha blockers: every core workflow passes the [alpha gate](roadmap.md#alpha-
|
||||
Margins are dragged on the rulers (#792). Remaining: pictures in headers/footers, Different First Page / Odd & Even pages. Desktop now submits directly through craft-print with printer choice, copies, duplex and grayscale; browser printing stays available. Print ranges and driver tray/options UI remain. **Estimate:** 5–10 h.
|
||||
|
||||
### 15. Remaining functions and an oracle suite (F)
|
||||
- 18 missing, 9 stubs; no Excel-computed oracle corpus; #137, #138. **Estimate:** 16–26 h.
|
||||
- 20 missing, 9 stubs; no Excel-computed oracle corpus; #137, #138. **Estimate:** 17–29 h.
|
||||
- 21 missing, 9 stubs; no Excel-computed oracle corpus; #137, #138. **Estimate:** 18–30 h.
|
||||
- 18 missing, 9 stubs; no Excel-computed oracle corpus; #137, #138. **Estimate:** 18–30 h.
|
||||
- 9 missing, 9 stubs; no Excel-computed oracle corpus; #137, #138. **Estimate:** 15–25 h.
|
||||
[function-parity.md](function-parity.md)
|
||||
|
||||
### 16. Collaboration and review (F)
|
||||
@@ -212,6 +209,7 @@ No alpha blockers: every core workflow passes the [alpha gate](roadmap.md#alpha-
|
||||
| 2026-10-15 | minor | §13: Solver prepares reports before committing the solution, model and report sheets together; report refusal preserves the workbook and Undo/Redo (#1050) |
|
||||
| 2026-10-13 | trivial | §4: multi-level category axes landed |
|
||||
| 2026-10-12 | minor | §9: next/previous sheet commands retain the current visible sheet and selection when there is no visible destination |
|
||||
| 2026-10-12 | minor | §8, §15: GETPIVOTDATA added (9 functions missing) |
|
||||
| 2026-10-12 | minor | rows auto-fit oversized fonts on open and whole-row/column formatting (#833) |
|
||||
| 2026-10-12 | minor | Page Layout view: dragging margins on the rulers (#792) removed from the §14 remainder |
|
||||
| 2026-10-12 | minor | §13: Forecast Sheet Forecast Start (hindcast) landed (#785) |
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Target-app parity: GridCraft vs Microsoft Excel
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-02 · **Change:** minor (form controls; catalog 281 / 296; earlier: insert objects: equations; earlier: what-if and analysis: Solver Sensitivity report; no score change; earlier: chart resizing no longer listed as missing; no score change; earlier: what-if and analysis: Analysis ToolPak has all 19 tools; earlier: page layout and print: Page Setup's page order; no score change; earlier: charts: data tables with XLSX round-trip and print/PDF; no score change; earlier: what-if and analysis: Solver Options; the Insert Function dialog is named as in Excel; no score change; earlier: Solver Load/Save Model and Reset All; automation: macro interface; catalog count 276 / 292, as `cargo xtask parity` measures; automation: typed macros in the engine; several windows: a native window per workbook window, New Window on the same workbook, Arrange All; no score change) · **Target:** Microsoft Excel (Microsoft 365)
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-15 · **Change:** minor (performance: formula entry and XLSX save win back time lost since 23829d8c (#2654), 465 → 420 ms and 540 → 488 ms on the 100k-row benchmark; Sandbox refuses fcntl's asynchronous notification and the socket ioctls that notify another process on Linux (#3846); CI provisions pinned fonts for coverage tests; no score change; earlier: form controls; catalog 281 / 296; earlier: insert objects: equations; earlier: what-if and analysis: Solver Sensitivity report; no score change; earlier: chart resizing no longer listed as missing; no score change; earlier: what-if and analysis: Analysis ToolPak has all 19 tools; earlier: page layout and print: Page Setup's page order; no score change; earlier: charts: data tables with XLSX round-trip and print/PDF; no score change; earlier: what-if and analysis: Solver Options; the Insert Function dialog is named as in Excel; no score change; earlier: Solver Load/Save Model and Reset All; automation: macro interface; catalog count 276 / 292, as `cargo xtask parity` measures; automation: typed macros in the engine; several windows: a native window per workbook window, New Window on the same workbook, Arrange All; no score change) · **Target:** Microsoft Excel (Microsoft 365)
|
||||
|
||||
This is the authoritative parity assessment. [`ROADMAP.md`](../ROADMAP.md) summarizes it,
|
||||
[`gaps.md`](gaps.md) lists every shortfall, and the area checklists hold the detail:
|
||||
@@ -14,8 +14,8 @@ generated ribbon checklist is [`parity-checklist.md`](parity-checklist.md).
|
||||
|---|---|---|
|
||||
| Feature breadth (weighted by use) | **~75%** | estimated from the area table below; anchored on two measurements |
|
||||
| Ribbon and menu catalog | **281 / 296 (94.9%)** | measured: `cargo xtask parity` (`crates/engine/src/catalog.rs` ∩ registered command ids) |
|
||||
| Worksheet functions, by name | **513 / 523 (98.1%)** | measured: registered functions vs Microsoft's published function list (method below) |
|
||||
| Worksheet functions that do real work | **504 / 523 (96.4%)** | measured: excludes 9 stubs (7 CUBE functions, WEBSERVICE, FILTERXML) |
|
||||
| Worksheet functions, by name | **514 / 523 (98.3%)** | measured: registered functions vs Microsoft's published function list (method below) |
|
||||
| Worksheet functions that do real work | **505 / 523 (96.6%)** | measured: excludes 9 stubs (7 CUBE functions, WEBSERVICE, FILTERXML) |
|
||||
| **Ready for real work** | **~50%** | estimated; written weights below (51.6 computed) |
|
||||
| **Mainstream practitioner** | **~50%** | estimated; [method](#mainstream-practitioner) (69.5 depth × 0.90 × 0.92 × 0.88 = 50.6) |
|
||||
| **Essentials user** | **~63%** | estimated; [method](#essentials-user) (80.2 depth × 0.92 × 0.95 × 0.90 = 63.1) |
|
||||
@@ -81,11 +81,11 @@ performance 8, stability 8, localization 4, hardware 2, platforms 2, ecosystem 2
|
||||
| Area | Weight | Breadth | Ready | Hours | Evidence |
|
||||
|---|---|---|---|---|---|
|
||||
| Formula language and calculation | 18 | ~92% | ~72% | 20–30 | A1/R1C1 parser, reference adjustment, dependency-graph recalc, dynamic arrays and `#SPILL!`, `A1#`, LET/LAMBDA and helpers, structured references, names, 3-D references. Open correctness bugs: 15-digit equality (#57), stale spills after structural edits and cleared blockers (#133, #139), 3-D span endpoint deletion (#140), sheet rename and qualified names (#134). Single-threaded |
|
||||
| Worksheet functions | 12 | 98.1% (measured) | ~82% | 16–26 | 513 / 523 names, 504 working. Missing: GETPIVOTDATA, IMAGE plus cloud functions. No conformance suite against Excel-computed oracles; edge-case bugs keep surfacing (#137, #138). [function-parity.md](function-parity.md) |
|
||||
| Worksheet functions | 12 | 98.3% (measured) | ~82% | 15–25 | 514 / 523 names, 505 working. Missing: IMAGE plus cloud functions. No conformance suite against Excel-computed oracles; edge-case bugs keep surfacing (#137, #138). [function-parity.md](function-parity.md) |
|
||||
| Editing, navigation, clipboard, fill | 12 | ~90% | ~70% | 15–25 | Point mode, F4, AutoComplete, Paste Special, AutoFill, Flash Fill, Find/Replace, Go To Special. Bugs: rectangular drag-select (#28), monthly fill (#132), cut across sheets (#128), Insert Copied Cells missing (#21), key tips only on part of the Home tab (#43; #33, #49). [ui-parity.md](ui-parity.md) |
|
||||
| Cell formatting, styles, conditional formatting | 10 | ~95% | ~80% | 8–14 | Full number-format language, borders, 47 cell styles, 60 table styles, all CF rule kinds including data bars, colour scales and icon sets. Gaps: font weights beyond regular/bold (#168), system fonts list (#4), themes |
|
||||
| Sort, filter, tables, validation, outline | 8 | ~82% | ~70% | 10–16 | Multi-level sort, AutoFilter, Advanced Filter, tables with totals, validation, outline, subtotals, consolidate. Advanced Filter copy-to preserves cells outside its result and rejects worksheet overflow (#1031). Bugs: subtotal header (#131), validation edits (#129), table style panic caught (#130); no slicers on tables |
|
||||
| PivotTables | 7 | ~65% | ~45% | 25–40 | Insert/Recommended, field list, three layouts, values on rows or columns, date grouping, show-values-as, refresh, calculated fields, XLSX round-trip. Missing: slicers, timelines, calculated items, PivotCharts, value/label filters, number grouping, GETPIVOTDATA, data-model pivots. Round-trip never checked in Excel |
|
||||
| PivotTables | 7 | ~65% | ~45% | 25–40 | Insert/Recommended, field list, three layouts, values on rows or columns, date grouping, show-values-as, refresh, calculated fields, GETPIVOTDATA, XLSX round-trip. Missing: slicers, timelines, calculated items, PivotCharts, value/label filters, number grouping, Generate GetPivotData, data-model pivots. Round-trip never checked in Excel |
|
||||
| Charts and sparklines | 8 | ~50% | ~30% | 40–60 | 25 chart kinds, all 2-D. Doughnut charts draw every series as a concentric ring (first series innermost), with editable hole size and first slice angle. The chart model holds title, legend position, a data-labels flag, gridlines flag, axis titles and chart data tables (legend keys, borders, XLSX round-trip and print/PDF); no axis scaling, error bars, per-point formatting, chart sheets, 3-D, surface, map, Pareto. Kinds survive XLSX round trip (#158, #161), except stock charts: only 3–4 series are a stock chart, and any other count is written and reimported as a line chart. [chart-parity.md](chart-parity.md) |
|
||||
| Page layout, print, PDF | 5 | ~80% | ~55% | 12–20 | Page setup, print titles, breaks, page order, Page Break Preview, headers/footers, PDF export and printing. Paper sizes match Japanese Excel: B4/B5/B6 are the JIS sizes, ISO B4/B5/B6 stay reachable by name, and Japanese Postcard (はがき), Japanese Double Postcard (往復はがき), the chou/kaku envelopes and A6 are available. No true Page Layout view; the PDF writer uses only the 14 standard fonts without embedding (no CJK or other non-Latin text in PDF); web print only exports (#141, #143) |
|
||||
| What-if and analysis | 4 | ~50% | ~40% | 22–35 | Goal Seek, Scenario Manager, data tables, Analysis ToolPak (all 19 tools, no charts), Solver (Simplex LP, a local nonlinear method and Evolutionary; Answer, Sensitivity and Limits reports; Load/Save Model, Reset All and Solver Options; no Population report), Forecast Sheet. Missing: Analyze Data |
|
||||
@@ -334,6 +334,7 @@ The inventory carried over from the 2026-10-07 ROADMAP.md, updated for what land
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-15 | minor | Performance: formula entry 465 → 420 ms and XLSX save 540 → 488 ms on the 100k-row benchmark (#2654); Sandbox refuses fcntl's asynchronous notification and notifying socket ioctls on Linux (#3846); CI provisions pinned fonts for coverage tests; no score change |
|
||||
| 2026-11-02 | minor | Form controls (buttons, scroll bars, spin buttons) in Insert objects and Automation; catalog 277 / 292 → 281 / 296 (Developer › Controls) |
|
||||
| 2026-11-02 | minor | Insert objects: equations; catalog count 277 / 292 (no score change) |
|
||||
| 2026-11-02 | minor | What-if and analysis: Solver Sensitivity report (no score change) |
|
||||
@@ -351,6 +352,7 @@ The inventory carried over from the 2026-10-07 ROADMAP.md, updated for what land
|
||||
| 2026-10-18 | trivial | Stale chart notes: all chart kinds survive XLSX round-trip (PRs #158, #161) and trendlines landed |
|
||||
| 2026-10-16 | minor | Advanced Filter copy-to clears only its actual output and rejects overflow without changing cells (#1031) |
|
||||
| 2026-10-15 | minor | Row auto-fit: line breaks count only in wrapping cells (Excel: wrap off shows one line, AutoFit gives one line); unwrapped multi-line cells from files no longer grow rows on open (no score change) |
|
||||
| 2026-10-12 | minor | Worksheet functions 514 / 523 (98.3%; 505 working): GETPIVOTDATA |
|
||||
| 2026-10-21 | minor | Automation: typed macros in the engine and `macro.*` commands, no interface yet (no score change); catalog 274 / 290 → 275 / 291 (View › Macros › Record Macro) |
|
||||
| 2026-10-12 | minor | Essentials AutoFit evidence: rows auto-fit oversized fonts on open and row formatting (#833) |
|
||||
| 2026-10-12 | minor | Sheet tabs: reveal the selected tab on navigation and resize while preserving manual scrolling (#681); no score change |
|
||||
|
||||
Reference in New Issue
Block a user