Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/KNOWN-ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/error-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 38 additions & 0 deletions docs/exporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>`) 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 `<sheet name>.csv` in one zip, each exactly the csv file
Expand Down
1 change: 1 addition & 0 deletions docs/formats.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Loading
Loading