mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-18 16:14:57 +00:00
Docs: CSV export wording matches the code; inferred & boundaries marked
From 1E+15, CSV export writes the shortest round-trip digits, not &'s 15 digits. 'Every digit' now applies only to integers below 1e16. The open/save round-trip claim is narrowed to files GridCraft wrote. The doc now lists what a foreign CSV loses on its first save: 16-17-digit decimals are cut to 15 digits, and scientific input is rounded to its 0.00E+00 format. The 21-character switch is Excel-verified only for positive 15-digit mantissas. Shorter mantissas from 1E-6 to 1E-9 and negatives are marked as inferred, and the doc states the sign isn't counted. The function-parity 'was' value is corrected to main's 0.00000001.
This commit is contained in:
1 parent
bf9b3cb9b1
commit
9cbbaaeaed
5 files changed
+16
-11
No files matched your search
@@ -351,8 +351,11 @@ pub fn sort_compare(a: &Value, b: &Value) -> Ordering {
|
||||
|
||||
/// Number → text the way Excel converts in `&`, CONCAT and TEXTJOIN: at most 15 significant
|
||||
/// digits, rounded first; scientific from 1E+15, below 1E-9, and wherever the decimal would be
|
||||
/// longer than 21 characters (`0.` plus 19 decimals: `0.0000692361330972509` stays decimal,
|
||||
/// `1.28233995888454E-06` does not, as Excel caches them).
|
||||
/// longer than 21 characters, not counting the sign (`0.` plus 19 decimals). Excel-verified only
|
||||
/// for positive 15-digit mantissas: `0.0000692361330972509` stays decimal and
|
||||
/// `1.28233995888454E-06` does not, as Excel caches them. The limit for shorter mantissas from
|
||||
/// 1E-6 to 1E-9 (e.g. `0.0000099999999999999` decimal) and for negatives (sign excluded) are
|
||||
/// inferred.
|
||||
pub fn number_to_text(n: f64) -> String {
|
||||
if n == 0.0 || !n.is_finite() {
|
||||
return "0".into();
|
||||
|
||||
@@ -95,8 +95,9 @@ pub fn cell_text(wb: &Workbook, sheet: &Sheet, c: CellRef) -> String {
|
||||
/// A cell's value with its number format applied, independent of column width: no `#####`
|
||||
/// and no General narrowing (Save As CSV/Text writes this). Formulas give their result. A number
|
||||
/// shown as General (also through a coloured or sectioned General, or a Text format) is written
|
||||
/// as [`format_value_full`] writes it: `&`'s 15 significant digits without an exponent, an integer
|
||||
/// below 1e16 with every digit (`124412140710`, not `1.24412E+11`). Excel writes the cell display.
|
||||
/// as [`format_value_full`] writes it, never with an exponent: `&`'s 15 significant digits below
|
||||
/// 1E+15 (`124412140710`, not `1.24412E+11`), the shortest round-trip digits from 1E+15 (every
|
||||
/// integer below 1e16 exactly). Excel writes the cell display.
|
||||
pub fn value_text(wb: &Workbook, sheet: &Sheet, c: CellRef) -> String {
|
||||
let style = wb.styles.get(sheet.style_id(c));
|
||||
with_fill_space(format_value_full(&sheet.value(c), &parsed(style.num_fmt.as_str()), wb.date_system))
|
||||
|
||||
@@ -231,10 +231,11 @@ pub fn source_dir(path: &str) -> Option<std::path::PathBuf> {
|
||||
/// Save As CSV/Text writes "the text and values as they are displayed in cells" with "all
|
||||
/// characters in each cell" (Microsoft Support, *Excel formatting and features that are not
|
||||
/// transferred to other file formats*): number formats applied, never column-width `#####`.
|
||||
/// One intentional difference: a number shown as General is not narrowed to the cell width but
|
||||
/// written as `&` converts it (15 significant digits) without an exponent, and an integer below
|
||||
/// 1e16 with every digit, so long identifiers survive a reopen and save
|
||||
/// (`gridcraft_numfmt::format_value_full`).
|
||||
/// One intentional difference: a number shown as General is not narrowed to the cell width and
|
||||
/// never gets an exponent (`gridcraft_numfmt::format_value_full`). Below 1E+15 it is written as
|
||||
/// `&` converts it (15 significant digits); from 1E+15 as the shortest digits that read back as
|
||||
/// the same value (every integer below 1e16 exactly, so long identifiers survive); small numbers
|
||||
/// that `&` writes in scientific notation as their 15 digits in full.
|
||||
fn csv(wb: &Workbook, sh: &Sheet, delimiter: u8) -> Result<Vec<u8>> {
|
||||
gridcraft_xlsx::write_csv(sh, delimiter, |c| crate::display::value_text(wb, sh, c)).map_err(|e| EngineError::Other(e.to_string()))
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# File-format parity
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-14 · **Change:** minor (CSV/text export writes every General number with `&`'s 15 digits, never an exponent; integers below 1e16 keep every digit) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-10-14 · **Change:** minor (CSV/text export writes General numbers without an exponent: `&`'s 15 digits below 1E+15, the shortest round-trip digits from 1E+15, so integers below 1e16 keep every digit) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
|
||||
Every format Excel opens or saves, with GridCraft's read and write support, fidelity and tests.
|
||||
Part of [target-app-parity.md](target-app-parity.md). **File formats: ~50% ready, 80–120 h**
|
||||
@@ -41,7 +41,7 @@ and repair-free opening remain unverified.
|
||||
|
||||
| Format | Excel | GridCraft read | GridCraft write | Notes |
|
||||
|---|---|---|---|---|
|
||||
| `.csv` UTF-8 / Windows / Mac / MS-DOS | R/W | yes (UTF-8 and UTF-16 BOMs, UTF-8, Windows-1252 fallback; delimiter detection) | yes (UTF-8 without BOM, CRLF; a file opened as CSV is saved with the separator it was read with, so a `;` file stays `;`; otherwise `,`) | Formatted numbers and formula results are written as displayed, as in Excel (never column-width `#####`). **Intentional difference:** Excel writes a General number as the cell displays it (`1.24412E+11`, `0.333333333`); GridCraft writes it with the 15 significant digits `&` gives (`0.333333333333333`, `0.3`, not `0.30000000000000004`) but never with an exponent, since reopening the file would give the cell a scientific format that rounds it on the next save: a number of 1E+15 or more is written as the shortest digits that read back as the same value (every integer below 1e16 exactly, so 16-digit card and order numbers survive: `9007199254740993` is stored and written as `9007199254740992`, `12345678901234567` as `12345678901234568`), a small one as its 15 digits in full (`0.00000128233995888454`). A CSV opened and saved again is unchanged. The same applies to a coloured or sectioned General (`[Blue]General`, `General;[Red]-General`) and to a number in a Text (`@`) cell. No encoding choice on save. Re-import of a single-column export splits text (#127). A used range that would write more than 512 MiB (two far-apart cells span the whole rectangle) is refused with an error instead of being expanded (#528). |
|
||||
| `.csv` UTF-8 / Windows / Mac / MS-DOS | R/W | yes (UTF-8 and UTF-16 BOMs, UTF-8, Windows-1252 fallback; delimiter detection) | yes (UTF-8 without BOM, CRLF; a file opened as CSV is saved with the separator it was read with, so a `;` file stays `;`; otherwise `,`) | Formatted numbers and formula results are written as displayed, as in Excel (never column-width `#####`). **Intentional difference:** Excel writes a General number as the cell displays it (`1.24412E+11`, `0.333333333`); GridCraft writes it with the 15 significant digits `&` gives (`0.333333333333333`, `0.3`, not `0.30000000000000004`) but never with an exponent, since reopening the file would give the cell a scientific format that rounds it on the next save: a number of 1E+15 or more is written as the shortest digits that read back as the same value (every integer below 1e16 exactly, so 16-digit card and order numbers survive: `9007199254740993` is stored and written as `9007199254740992`, `12345678901234567` as `12345678901234568`), a small one as its 15 digits in full (`0.00000128233995888454`). A CSV GridCraft wrote, opened and saved again, is unchanged. A CSV from elsewhere can change on its first save: a decimal with 16 or 17 significant digits is cut to 15, as in Excel (`3.141592653589793` → `3.14159265358979`), and a number typed in scientific notation gets the `0.00E+00` format on open and is saved rounded to it (`1.23456789012346E-10` → `1.23E-10`, unchanged from before). The same applies to a coloured or sectioned General (`[Blue]General`, `General;[Red]-General`) and to a number in a Text (`@`) cell. No encoding choice on save. Re-import of a single-column export splits text (#127). A used range that would write more than 512 MiB (two far-apart cells span the whole rectangle) is refused with an error instead of being expanded (#528). |
|
||||
| `.txt` tab-delimited, Unicode text | R/W | yes (`.txt`, `.tsv`, `.tab`) | yes (displayed values, with General numbers as for `.csv`) | Text Import Wizard options partly via Text to Columns |
|
||||
| `.prn` formatted text (space-delimited) | R/W | no | no | |
|
||||
| `.dif`, `.slk` (SYLK) | R/W | no | no | Small, legacy |
|
||||
|
||||
@@ -108,7 +108,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-14 | minor | Number-to-text (`&`, CONCAT, TEXTJOIN, VALUETOTEXT, the IM functions' complex text, and also formula printing, pivot and chart labels) rounds to 15 significant digits before choosing decimal or scientific, so `=(1E15-0.5)&""` is `1E+15`, not `1000000000000000`; and below 1 it switches to scientific when the decimal would be longer than 21 characters, as Excel caches IMCSCH/IMEXP/IMTAN results: `1.28233995888454E-06`, `9.99999999999999E-09` (was `0.00000000999999999999999`), but `0.0000692361330972509` |
|
||||
| 2026-10-14 | minor | Number-to-text (`&`, CONCAT, TEXTJOIN, VALUETOTEXT, the IM functions' complex text, and also formula printing, pivot and chart labels) rounds to 15 significant digits before choosing decimal or scientific, so `=(1E15-0.5)&""` is `1E+15`, not `1000000000000000`; and below 1 it switches to scientific when the decimal would be longer than 21 characters (sign not counted), as Excel caches IMCSCH/IMEXP/IMTAN results: `1.28233995888454E-06`, so `9.99999999999999E-09` (was `0.00000001`), but `0.0000692361330972509`. Only 15-digit positive mantissas are Excel-verified; the limit for shorter mantissas and for negatives is inferred |
|
||||
| 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 |
|
||||
|
||||
Reference in new issue
Block a user