diff --git a/docs/KNOWN-ISSUES.md b/docs/KNOWN-ISSUES.md index 26e6cce..59b0f03 100644 --- a/docs/KNOWN-ISSUES.md +++ b/docs/KNOWN-ISSUES.md @@ -215,6 +215,11 @@ TabularExport picks a column type by overload resolution, and some lambdas do no - `writer.Merge(rows, columns)` makes the next cell the top-left of a merged range. The writer skips the covered positions — the row's next write lands after the range, later rows skip it too — and writes them itself. The import reads a merged range as its value in the top-left cell and empty cells elsewhere; csv writes exactly that. - A merge must end inside the sheet: ending a sheet (or the file) while a range still has rows to cover is refused. - xlsx holds at most 65,536 merged ranges per sheet; the next is refused with `write.too-many-merges`. +- xlsx with `SummaryRows.Below` and `ShownLevels`: a hidden group that ends the sheet has no row below it to carry its "+". Excel writes a cell-less row there, but the reader would hand that back as one more, empty row (and the import would count it as skipped), so the writer leaves it out: the group's rows open hidden, but its button shows "−" over them. End the sheet with a level-0 row, such as a grand total, and the button is right. +- xlsx with `SummaryRows.Above` and `ShownLevels`, opened in LibreOffice: LibreOffice reads a group's collapsed state from the row after the group, not from the parent row Excel reads it from, so the writer marks both. Where it cannot mark the row after, LibreOffice opens the group's rows hidden but with a "−" over them; Excel is right in every case: + - A hidden group that ends the sheet has no row after it, and for the same reason as above none is written. End the sheet with a level-0 row and both programs show "+". + - A hidden group followed by a row that heads a shown group of its own — a parent holding a hidden subgroup, followed by a parent with shown children (levels 0, 1, 2, 0, 1 with `ShownLevels = 2`). Excel reads the mark on that second parent as the state of its own group and would open it collapsed, so the writer leaves it unmarked. There is no workaround short of a row between them at the level of the second parent, before its children. + - A level that jumps by more than one (0 → 2): LibreOffice makes a group for each level, both over the same rows, and takes the mark on the row after them as the state of the outer group. With levels 0, 2, 0 and `ShownLevels = 2`, LibreOffice shows the level-1 group collapsed ("+") where Excel shows it expanded over its hidden level-2 rows ("−"), and the level-2 group opens with "−" over hidden rows once the outer one is expanded. The same rows are hidden in both. Write the levels one step at a time to avoid it. ### Data by column diff --git a/docs/error-codes.md b/docs/error-codes.md index 22ebb33..cced11a 100644 --- a/docs/error-codes.md +++ b/docs/error-codes.md @@ -25,7 +25,7 @@ from them. | `structure.sheet-missing`, `structure.sheet-changed`, `structure.header-row-missing`, `structure.header-changed` | `TabularStructureException`: the file is not the one the plan was built for | | `format.unsupported`, `format.corrupt`, `format.truncated` | `TabularFormatException`: not a format this library reads (.xls, .xlsb, .fods, another OpenDocument type, binary, an archive with nothing readable), or damaged, or cut off. A csv read with `CsvQuoteMode.Strict` is `format.corrupt` where its quoting would need a repair: a quoted field the file ends inside, or text after a closing quote | | `limit.exceeded` | `TabularLimitException`: a bound was exceeded; `Limit` names the option, `Maximum` its value | -| `write.too-many-rows`, `write.too-many-merges`, `write.too-many-styles` | `TabularWriteException`: the data reached a limit of the format while writing — more rows than the sheet holds (1,048,576 in xlsx and ods; 2,147,483,647, the largest row number the reader gives, in csv and a zip of csv; located at the last row the sheet holds, column 0), more merged ranges than an xlsx sheet holds (65,536; located where the range would begin), or a style rule's 4,097th distinct style in a file (located at its cell). Never `TabularLimitException`, which is a reader's bound. The file written so far is incomplete and must be discarded. | +| `write.too-many-rows`, `write.too-many-merges`, `write.too-many-styles`, `write.outline-level` | `TabularWriteException`: the data went past what the format, or the sheet's declared outline, allows, found while writing — more rows than the sheet holds (1,048,576 in xlsx and ods; 2,147,483,647, the largest row number the reader gives, in csv and a zip of csv; located at the last row the sheet holds, column 0), more merged ranges than an xlsx sheet holds (65,536; located where the range would begin), or a style rule's 4,097th distinct style in a file (located at its cell), or a row begun at an outline level the sheet does not declare (negative, deeper than `RowOutline.Levels`, or above 0 on a sheet without an `Outline`; located at the row that would have been written, column 0). Never `TabularLimitException`, which is a reader's bound. The file written so far is incomplete and must be discarded. | | `write.precision-loss`, `write.not-finite`, `write.date-out-of-range`, `write.text-too-long`, `write.too-many-lines`, `write.ambiguous-line-breaks`, `write.invalid-character` | `TabularWriteException`: a value the chosen format cannot hold exactly, found while writing; `SheetName`, `RowNumber`, `ColumnIndex` and `Header` say where. The file written so far is incomplete and must be discarded. In xlsx: a long a double cannot hold exactly (beyond ±2^53 only some are), or a decimal with more than 15 significant digits (precision-loss); a date before 1900-01-01 (date-out-of-range); text over 32,767 characters (text-too-long). In ods: the same precision rule as xlsx (precision-loss); text over 16,777,216 characters, the reader's limit, or text whose escaped form would exceed the reader's per-value token limit (text-too-long); no date limit. | This table is checked against the library's sources by `ErrorCodeCatalogTests`, in both directions. diff --git a/docs/exporting.md b/docs/exporting.md index 2d99526..4101303 100644 --- a/docs/exporting.md +++ b/docs/exporting.md @@ -163,6 +163,44 @@ A merge must end inside the sheet: ending the sheet or the file while a range st is refused. The import reads a merged range as its value in the top-left cell and empty cells elsewhere, and csv writes exactly that. A batch writes plain rows, so end a range before it. +### Row grouping (outline levels) + +A report whose rows form a hierarchy — a parent row followed by its children — can be grouped, so that +Excel and LibreOffice show outline controls and collapse and expand it. Set `Outline` on the sheet's +`SheetOptions` and begin each row at its level; `BeginRow()` is level 0, and the header row is always +level 0, never in a group. + +```csharp +--8<-- "samples/TriasDev.Tabular.Samples.Export/RowByRow.cs:outline" +``` + +- `Levels` is the deepest level the sheet uses, 1 to 7. It sizes the outline gutter and its level + buttons, so declare the deepest level you write: a sheet declared deeper shows extra buttons. +- `ShownLevels` is how many levels show when the file opens, counted as Excel's level buttons count + them: 1 shows the level-0 rows only, 2 shows levels 0 and 1. It ranges from 1 to `Levels`; null opens + every row. The rows below the shown levels are written hidden, and each group over them opens + collapsed, showing "+". They are still in the file: the import reads hidden rows as it reads any other. +- `SummaryRows` says whether a group's summary row sits `Above` it (a parent written before its + children, the default) or `Below` it (a subtotal written after its rows). It matters in xlsx only. An + ods file has no such setting; LibreOffice draws a group's button on the group's first row whatever + is declared. In xlsx with `SummaryRows.Above`, a collapsed group is marked both on the row before it, + which Excel reads, and on the row after it, which LibreOffice reads — except where that row heads a + shown group of its own, which Excel would then open collapsed. In a few shapes LibreOffice therefore + shows "−" over hidden rows: a collapsed group that ends the sheet (so too in Excel with + `SummaryRows.Below`), a hidden group followed by a parent with shown children, and a level that jumps + by more than one; see [Known issues](KNOWN-ISSUES.md). +- A level may rise by more than one from one row to the next (0 to 2), as Excel allows. +- Csv and a zip of csv sheets ignore the outline, as they ignore the other layout options. + +`Levels` outside 1 to 7, `ShownLevels` outside 1 to `Levels` or an undefined `SummaryRows` is refused +by `BeginSheet` with an `ArgumentOutOfRangeException`. A row level outside 0 to `Levels` — negative, +deeper than declared, or above 0 on a sheet without an `Outline` — is refused by `BeginRow(int)` with a +`TabularWriteException` coded `write.outline-level` (see [Error codes](error-codes.md)), as a level +comes from your data. + +A declared export (`TabularExport`) writes every row at level 0, so its builder refuses +`SheetOptions` with an `Outline` with an `ArgumentException`; write a grouped sheet row by row. + ## A zip of csv sheets `TabularFormat.Zip` writes each sheet as `.csv` in one zip, each exactly the csv file diff --git a/docs/formats.md b/docs/formats.md index 2534b94..c438b37 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -190,6 +190,7 @@ they can be, so the same data fails the same way whichever format is chosen. See | Rows per sheet, header included | 2,147,483,647 (the largest row number the reader gives) | the same | 1,048,576 | 1,048,576 | | Columns per sheet | 1 to 16,384 | 1 to 16,384 | 1 to 16,384 | 1 to 16,384 | | Styles, layout, widths | ignored | ignored | yes | yes | +| Row outline (grouping) | ignored | ignored | `outlineLevel` on each row, with the summary position and the collapsed state | nested `table:table-row-group` elements; no summary position (LibreOffice draws the button on a group's first row) | | Distinct styles per file | | | 4,096 | 4,096 | | Merged ranges per sheet | written as the value and empty fields | the same | 65,536 | no limit | | Text per cell | 16 M chars (the reader's field limit) | 16 M chars | 32,767 chars | 16 M chars, and the escaped text within the reader's token limit | diff --git a/docs/superpowers/plans/2026-11-27-row-outline.md b/docs/superpowers/plans/2026-11-27-row-outline.md new file mode 100644 index 0000000..2d71623 --- /dev/null +++ b/docs/superpowers/plans/2026-11-27-row-outline.md @@ -0,0 +1,189 @@ +# Row grouping (outline levels) Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Rows written at an outline level (0–7) in the xlsx and ods writers, summary rows above or below, a sheet that can open collapsed to a level — csv ignores it, files without an outline unchanged byte for byte. + +**Architecture:** `SheetOptions.Outline` (a new `RowOutline` record) declares the outline when the sheet begins; `TabularWriter.BeginRow(int)` checks each row's level and passes it through `ISheetWriter.BeginRow(int level)`. The xlsx writer writes the outline into the sheet head and row attributes, holding one row back only for summary-above + collapsed; the ods writer opens and closes nested `table:table-row-group` elements as the level changes. + +**Tech Stack:** C# / .NET 10 (tests also net11.0), xUnit v3 on Microsoft.Testing.Platform, no third-party runtime dependencies. + +**Spec:** `docs/superpowers/specs/2026-11-27-row-outline-design.md` — read it first; this plan does not repeat its reasoning. + +## Global Constraints + +- Public types in namespace `TriasDev.Tabular`; every public member in `src/TriasDev.Tabular/PublicAPI.Unshipped.txt`. +- `Levels` 1 to 7; `ShownLevels` 1 to `Levels` or null; `SummaryRows` default `Above`. +- New error code exactly `write.outline-level`, constant `ErrorCodes.Write.OutlineLevel`. +- `Outline = null` and `BeginRow()` / `BeginRow(0)` produce today's bytes in csv, xlsx, ods and zip. +- No buffering beyond one row; on a sheet without an outline, at most one branch added to the row path. +- xlsx head order: `sheetPr`, `sheetViews`, `sheetFormatPr`, `cols`, `sheetData`; ``. +- Nothing product-specific (consumer names, internal paths) in code, docs or commit messages; the repo is public. +- Pull request title: `feat: group rows into outline levels in the xlsx and ods writers`, squash-merged, description written by hand (CONTRIBUTING.md, "Commits and pull requests"). + +## Review Focus + +- An outline together with `FreezeRows`, column widths, `AutoFilter` and merges on one sheet: the head keeps the schema order, and a held row is written before ``, `` and ``. → Task 5, `HeldRowPrecedesFilterAndMerges`; Task 4, `HeadKeepsSchemaOrderWithFreezeAndWidths`. +- Several sheets: an outlined sheet followed by one without an outline (and the reverse) — groups closed, held row emitted, state reset; the plain sheet's part is byte-equal to the same sheet written alone. → Task 4 `NextSheetStartsWithoutOutlineState`, Task 6 `GroupsCloseAtNextSheetAndAtCompletion`. +- An outlined sheet with only the header, or only level-0 rows: a valid file, no empty `table-row-group`, no `outlineLevel` attribute. → Task 4 and Task 6, `OutlineWithoutDeeperRowsWritesNoGroups`. +- `WriteBatch` rows (level 0) after rows at level 2: ods closes both groups; xlsx gives the held row its `collapsed` from the batch's first row. → Task 5 `BatchRowEndsGroups`, Task 6 `BatchRowEndsGroups`. +- A group that runs to the last row of the sheet, for above and below, and a jump 0 → 2 followed by a fall 2 → 0. → Task 4 `TrailingGroupBelow`, Task 5 `LastHeldRowIsWritten`, Task 6 `JumpAndFallNestCorrectly`. + +--- + +### Task 1: LibreOffice confirms the ods collapse markup (gate, by hand) + +**Files:** none in the repo. Hand-made files, written by a throwaway script outside the repo: +`shown-1.ods`, `shown-2.ods`, `expanded.ods` — rows `Name`(0), `F1`(0), `D1a`(1), `P1`(2), `D1b`(1), `F2`(0), `X (0->2)`(2), `D2b`(1), `F3`(0); a group opened for level L ≥ `ShownLevels` carries `table:display="false"`, a row at level ≥ `ShownLevels` carries `table:visibility="collapse"`. + +- [ ] **Step 1: The owner opens the three files in LibreOffice.** + Expected: `shown-1.ods` shows only `Name`, `F1`, `F2`, `F3`, each group with "+", opening on the first click; `shown-2.ods` shows level 0 and 1 rows, `P1` and `X` hidden behind "+"; `expanded.ods` shows every row with "−". +- [ ] **Step 2: Record the result** in the spec's "What the formats do (verified)" section (one sentence, dated). If a collapsed group shows "−" or needs two clicks, stop: the ods section of the spec is revised before Task 6. + +### Task 2: Pin today's bytes + +**Files:** +- Create: `tests/TriasDev.Tabular.Tests/Writing/OutlineUnchangedBytesTests.cs` + +**Interfaces:** +- Produces: `OutlineUnchangedBytesTests.Write(TabularFormat, Action?)` — the reference sheet, reused by Task 3. + +- [ ] **Step 1: Write the test on `main`'s code, before any change.** One sheet `"data"` with five columns (one with a width), a `HeaderStyle`, `FreezeRows = 1`, `FreezeColumns = 1`, `AutoFilter = true`, a style on one cell, a 2×2 merge, 20 rows of text, long, decimal, date, bool; a second sheet `"second"` with one row. `[Theory]` over `Csv`, `Xlsx`, `Ods`, `Zip`: `Assert.Equal(Expected[format], Convert.ToHexString(SHA256.HashData(bytes)))`. +- [ ] **Step 2: Run it, copy the four hashes it reports into `Expected`, run again.** + Run: `dotnet test --project tests/TriasDev.Tabular.Tests --filter "FullyQualifiedName~OutlineUnchangedBytesTests"` + Expected: PASS for all four formats, on net10.0 and net11.0. +- [ ] **Step 3: Commit** — `test: pin the bytes the writers write today`. + +### Task 3: Outline options, the level on a row, and its refusals + +**Files:** +- Create: `src/TriasDev.Tabular/Writing/RowOutline.cs` (`RowOutline`, `SummaryRows`) +- Modify: `src/TriasDev.Tabular/Writing/SheetOptions.cs` (property `Outline`, method `OutlineProblem`) +- Modify: `src/TriasDev.Tabular/Writing/TabularWriter.cs` (`BeginSheet` check at `:246`, `BeginRow(int)`, `StartRow` at `:948`) +- Modify: `src/TriasDev.Tabular/Writing/ISheetWriter.cs`, `Xlsx/XlsxSheetWriter.cs:119`, `Ods/OdsSheetWriter.cs:105`, `Csv/CsvSheetWriter.cs:77`, `Archive/ZipCsvSheetWriter.cs:88` (`BeginRow(int level)`; all four ignore the level in this task) +- Modify: `src/TriasDev.Tabular/Writing/TabularExportBuilder.cs:135` (refuse `Outline`) +- Modify: `src/TriasDev.Tabular/Abstractions/ErrorCodes.cs` (`Write.OutlineLevel`), `docs/error-codes.md:28` row, `src/TriasDev.Tabular/PublicAPI.Unshipped.txt` +- Test: `tests/TriasDev.Tabular.Tests/Writing/RowOutlineTests.cs`, `tests/TriasDev.Tabular.Tests/Writing/TabularExportSheetOptionsTests.cs` + +**Interfaces:** +- Produces: + - `public sealed record RowOutline { public required int Levels { get; init; } public SummaryRows SummaryRows { get; init; } public int? ShownLevels { get; init; } }` + - `public enum SummaryRows { Above = 0, Below = 1 }` + - `public RowOutline? SheetOptions.Outline { get; init; }` + - `internal ArgumentOutOfRangeException? SheetOptions.OutlineProblem(string paramName)` + - `public void TabularWriter.BeginRow(int outlineLevel)`; `BeginRow()` calls the same path with 0 + - `void ISheetWriter.BeginRow(int level)` — replaces `BeginRow()`; `options` passed to `ISheetWriter.BeginSheet` carries `Outline` + - `ErrorCodes.Write.OutlineLevel = "write.outline-level"` + +- [ ] **Step 1: Write the failing tests** in `RowOutlineTests`: + - `RefusesLevelsOutsideOneToSeven` — `[Theory]` 0, 8, −1: `BeginSheet(…, new SheetOptions { Outline = new RowOutline { Levels = n } })` throws `ArgumentOutOfRangeException` with `ParamName == "options"`. + - `RefusesShownLevelsOutsideOneToLevels` — `Levels = 2`, `ShownLevels` 0 and 3 → `ArgumentOutOfRangeException`; 1 and 2 accepted. + - `RefusesAnUndefinedSummaryRows` — `(SummaryRows)7` → `ArgumentOutOfRangeException`. + - `RefusesALevelOutsideTheOutline` — `[Theory]` over all four formats × (level −1, `Levels` + 1 with `Levels = 2`, level 1 with no `Outline`): `BeginRow(level)` after one written row throws `TabularWriteException` with `Code == "write.outline-level"`, `SheetName == "data"`, `RowNumber == 3` (header 1, one row 2, refused 3), `ColumnIndex == 0`, `Header` = first header; the next call throws `InvalidOperationException` (faulted). + - `RowLimitIsJudgedBeforeTheLevel` — xlsx, `writer.MaxRows = 3` (as `RowNumberLimitTests.TheRowPastTheLimitIsAWriteErrorNotAReaderBound` does), `Levels = 1`: after two rows, `BeginRow(5)` throws `write.too-many-rows`, not `write.outline-level`. + - `AcceptsEveryLevelUpToLevels` — `Levels = 7`, rows at 0..7 and back to 0 in every format; `CompleteAsync` succeeds. + - `CsvIgnoresTheOutline` — `[Theory]` `Csv`, `Zip`: rows at levels 0,1,2,1,0 with an `Outline` give the same bytes as the same rows with `BeginRow()` and no `Outline`. + - In `TabularExportSheetOptionsTests`: `BuildRefusesAnOutline` — `.Sheet(new SheetOptions { Outline = new RowOutline { Levels = 1 } }).Build()` throws `ArgumentException`. +- [ ] **Step 2: Run, verify they fail** (compile errors: `RowOutline` not defined). + Run: `dotnet test --project tests/TriasDev.Tabular.Tests --filter "FullyQualifiedName~RowOutlineTests|FullyQualifiedName~TabularExportSheetOptionsTests"` +- [ ] **Step 3: Implement.** `OutlineProblem` returns null for `Outline == null`. `BeginSheet` calls it right after `FreezeProblem` and keeps the declared `Levels` (0 when no outline) in a field. `StartRow(int level)`: the row-limit check first (unchanged), then `level < 0 || level > _outlineLevels` → `throw Faulting(OutlineLevel(level))` located at `_rowNumber + 1`, then `_rowNumber++` and `_sheet.BeginRow(level)`. The header row passes 0. Messages: with an outline — `Row {row} of sheet "{name}" is at outline level {level}; the sheet's outline holds levels 0 to {Levels}.`; without — `…; the sheet has no outline (SheetOptions.Outline), so its rows are at level 0.` Add the code to the `write.*` row of `docs/error-codes.md` with its location ("located at the row that would have been written, column 0") so `ErrorCodeCatalogTests` passes. Add every new public member to `PublicAPI.Unshipped.txt`. Doc comments as in the spec's API block. +- [ ] **Step 4: Run the new tests, `OutlineUnchangedBytesTests` and `ErrorCodeCatalogTests`.** Expected: PASS. +- [ ] **Step 5: Commit** — `feat: declare a sheet's row outline and begin a row at a level`. + +### Task 4: xlsx — outline head, row levels, hidden rows, collapsed with summary below + +**Files:** +- Modify: `src/TriasDev.Tabular/Xlsx/XlsxSheetWriter.cs` (`BeginSheet` `:93`, `BeginRow` `:119`, `EndRow` `:227`, `CloseSheet` `:496`) +- Test: `tests/TriasDev.Tabular.Tests/Writing/XlsxOutlineTests.cs` + +**Interfaces:** +- Consumes: `ISheetWriter.BeginRow(int level)`, `SheetOptions.Outline` (Task 3). + +- [ ] **Step 1: Write the failing tests.** Read `xl/worksheets/sheet1.xml` with `SheetLayoutTests.Write` / `SheetLayoutTests.Entry`; rows of levels 0,1,2,1,0 unless stated. + - `HeadKeepsSchemaOrderWithFreezeAndWidths` — `Levels = 2`, `FreezeRows = 1`, a width: the indexes of ``, ``, ``, ``, `` are increasing. + - `SummaryBelowWritesNoSheetPr` — `SummaryRows.Below`: no `` present. + - `RowsCarryTheirLevel` — row 3 has `outlineLevel="1"`, row 4 `outlineLevel="2"`, rows 1, 2, 6 have no `outlineLevel`; no `hidden` or `collapsed` anywhere without `ShownLevels`. + - `ShownLevelsHidesDeeperRows` — `ShownLevels = 1`, `Below`: rows 3–5 carry `hidden="1"`, rows 1, 2, 6 do not. + - `CollapsedBelowMarksTheRowAfterTheGroup` — `Below`, `ShownLevels = 1`, levels 0,1,2,1,0: row 6 has `collapsed="1"`; with `ShownLevels = 2`: row 5 (level 1 after a hidden level-2 row) has `collapsed="1"` and row 6 has none. + - `TrailingGroupBelow` — `Below`, `ShownLevels = 1`, the last row at level 1: implement the spec's builder decision (a cell-less `` only if `SheetLayoutTests.Rows` and `TabularImporter` read the same rows back as without it; otherwise no such row and a `docs/KNOWN-ISSUES.md` entry). The test asserts whichever was chosen, and that the read-back rows equal the written rows. + - `OutlineWithoutDeeperRowsWritesNoGroups` — `Levels = 1`, header only; and header + level-0 rows: valid file, no `outlineLevel` attribute. + - `NextSheetStartsWithoutOutlineState` — sheet 1 outlined (`Below`, `ShownLevels = 1`), sheet 2 plain: `sheet2.xml` equals the `sheet1.xml` of the same plain sheet written alone. + - `ReadsBackTheSameRows` — the round trip: `SheetLayoutTests.Rows` of an outlined file equals that of the same data written without an outline, hidden rows included. +- [ ] **Step 2: Run, verify they fail.** + Run: `dotnet test --project tests/TriasDev.Tabular.Tests --filter "FullyQualifiedName~XlsxOutlineTests"` +- [ ] **Step 3: Implement.** In `BeginSheet`, with `Outline` set: `` right after `XlsxParts.WorksheetStart` for `Above`, and the `sheetFormatPr` between `AppendFreeze` and `AppendWidths`. Row start tag: `outlineLevel`, `hidden`, `collapsed` per the spec's xlsx rules; for `Below`, remember the previous row's level and whether it was hidden. `SummaryRows.Above` with `ShownLevels` is Task 5: in this task it writes `hidden` but no `collapsed`. Reset all outline state in `BeginSheet`. +- [ ] **Step 4: Run `XlsxOutlineTests`, `OutlineUnchangedBytesTests`, `XlsxRoundTripTests`, `SheetLayoutTests`.** Expected: PASS. +- [ ] **Step 5: Commit** — `feat: write row outline levels in xlsx`. + +### Task 5: xlsx — collapsed with summary above (one row held back) + +**Files:** +- Modify: `src/TriasDev.Tabular/Xlsx/XlsxSheetWriter.cs` +- Test: `tests/TriasDev.Tabular.Tests/Writing/XlsxOutlineTests.cs` + +**Interfaces:** +- Consumes: Task 4's row start tag and outline state. + +- [ ] **Step 1: Write the failing tests** (`Above`, `ShownLevels = 1` unless stated). + - `CollapsedAboveMarksTheParentRow` — levels 0,1,2,1,0: row 2 has `collapsed="1"`, row 3 (level 1, hidden, followed by a hidden level 2) has `collapsed="1"`, rows 4–6 none. With `ShownLevels = 2`: row 2 none, row 3 `collapsed="1"`. + - `LastHeldRowIsWritten` — the sheet's last row at level 1, then `CompleteAsync`: it is present, before ``, without `collapsed`; and a last row at level 0 after a parent with no children: no `collapsed`. + - `HeldRowPrecedesFilterAndMerges` — `AutoFilter = true`, a merge on row 2: the last row precedes ``, which precedes `` before the level-2 row, one `` before the level-1 row, one before the last row; groups balanced. + - `ShownLevelsCollapses` — `ShownLevels = 1`, levels 0,1,2,1,0: both groups carry `table:display="false"`, rows at level ≥ 1 carry `table:visibility="collapse"`; with `ShownLevels = 2`: only the inner group and the level-2 row. + - `SummaryRowsWritesNothing` — `Above` and `Below` give identical `content.xml`. + - `GroupsCloseAtNextSheetAndAtCompletion` — the last row of sheet 1 at level 2, sheet 2 begins: two closings before the first ``; the same at completion for the last sheet. + - `OutlineWithoutDeeperRowsWritesNoGroups` — header only, and level-0 rows only: no `table-row-group`. + - `BatchRowEndsGroups` — rows at 0, 2, then a `WriteBatch` row: two closings before the batch row. + - `ReadsBackTheSameRows` — as in Task 4, for ods. +- [ ] **Step 2: Run, verify they fail.** + Run: `dotnet test --project tests/TriasDev.Tabular.Tests --filter "FullyQualifiedName~OdsOutlineTests"` +- [ ] **Step 3: Implement** per the spec's ods section: a depth counter; open/close in `BeginRow(level)` before `