Skip to content

Open SYLK (.slk) files: values, R1C1 formulas, number formats, widths (#1481) - #3253

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
hectorviov:feat/sylk-import
Nov 3, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
hectorviov:feat/sylk-import

Conversation

@hectorviov

Copy link
Copy Markdown
Contributor

Fixes #1481

What changed

GridCraft now opens SYLK (.slk) files. The new reader is crates/engine/src/io/sylk.rs, and FileKind::Sylk sends .slk files to it. It reads:

  • Values: numbers, "text", TRUE/FALSE and errors. ;; inside a field is a literal semicolon. Text is kept between its outer quotes exactly as written, which is how Excel reads it.
  • Formulas: converted from R1C1 to A1 the way Excel converts them when it opens the file. That covers relative and absolute references, ranges, whole columns (C4 becomes $D:$D) and whole rows (R3 becomes $3:$3). Shared formulas (S;R…;C…) are the other cell's formula moved to this cell. Function and name words such as ROUND, RATE or R2D2 are left alone, and so are quoted text and quoted sheet names. A reference that falls off the sheet becomes #REF!. Each formula keeps the value cached in the file.
  • Number formats: P;P… builds the list of formats and F;P<n> applies one. Like Excel, an F record with only X formats the cell on the current row.
  • Column widths: F;W<first> <last> <width>, in characters.
  • Sheet name: the file name, as for CSV.

Saving as .slk reports that SYLK is import only, the same as ODS and XLSB. .slk is also added to the Open dialog's Spreadsheets filter on desktop and web. A file that doesn't start with ID is refused. Damaged records (positions off the sheet, formulas that don't parse) are skipped with one warning.

Three-way comparison

I wrote one SYLK file by hand from the public format description. It has values, formulas, a shared formula, number formats and widths, and I opened it in each app:

Cell GridCraft main GridCraft with this PR Excel
A1 ID (the file is read as CSV text, one record per row) Item Item
A2 — Bolts; small Bolts; small
D2 — =B2*C2 → 4.2 =B2*C2 → 4.2
E2 — =$B$2+B3 → 52 =$B$2+B3 → 52
E3 — =IF($D$4>5,"big","small") → big same
G3 (shared) — =D3*2 → 9.6 =D3*2 → 9.6
G4 — =SUM($D:$D) → 18 =SUM($D:$D) → 18
C2 / C3 format — 0.00 / General 0.00 / General
B5 — 45000 shown as yyyy-mm-dd same format
widths A / B / C — 18 / 9 / 9 18 / 9 / 9

The Excel column was read by AppleScript from Excel for Mac after it opened the same file. Excel's sandbox wouldn't let it save a SYLK file somewhere I could read, so the test input is my own text and not an Excel export.

Tests

  • io::tests::sylk_files_open_with_values_formulas_formats_and_widths covers the file above. It fails on main, where A1 reads "ID".
  • io::tests::sylk_r1c1_formulas_become_a1 has 13 conversion cases, including names that look like references, quoted text and sheets, and references off the sheet.
  • io::tests::sylk_rejects_other_files_and_survives_damage checks a file without ID, positions off the grid, a number that overflows, an unknown format index, a reversed width range and an unparseable formula.
  • cargo xtask ci passes.

Anything a reviewer should look at first

  • The reader lives in the engine, not in crates/xlsx, because the formula text goes through Formula::new like the other importers. The R1C1 conversion is its own small scanner, so the xlsx crate is untouched.
  • Fonts and cell styles are not read. Excel keeps them in P;F font records, and the F;S flags I tried (bold, italic) changed nothing in Excel either. Row heights, names and comments aren't read yet. The file-format parity row lists these.
  • A file that isn't valid UTF-8 is read as Latin-1. Older exports use a single-byte code page, and Excel's ESC sequences for accented characters aren't decoded.

🤖 Generated with Claude Code

A small reader for the SYLK text format: cell values (numbers, text,
booleans, errors), formulas converted from R1C1 to A1 as Excel does
(relative/absolute references, ranges, whole rows and columns, shared
formulas) with their cached results, number formats (P / F;P) and
column widths (F;W). Import only; saving as .slk says so. The sheet is
named after the file, and damaged records are skipped with a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 8 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 178f3eb and 94b4f6a.

Files selected for processing: 7
  • apps/gridcraft-web/src/web.rs
  • apps/gridcraft/src/main.rs
  • crates/engine/src/io.rs
  • crates/engine/src/io/sylk.rs
  • crates/engine/src/io/tests.rs
  • docs/file-format-parity.md
  • docs/gaps.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 3bdfa6e into storytold:main Nov 3, 2026
1 check passed
h-a-n-a-s-h-i pushed a commit that referenced this pull request Nov 3, 2026
- #3223: sniff the first 64 KiB for a web page and skip JSON and files over the text-import cap, so
  every CSV/TSV is no longer decoded in full before the size check.
- #3253: SYLK relative offsets use checked arithmetic (no overflow on R[9223372036854775807]); at
  most 1024 column-width records are kept; regression test.
- #3254: a single selected merged cell searches the whole sheet, as one selected cell does.
- #3252: the formula bar's height cap is half the room below the ribbon, not half the window, so
  the worksheet stays visible in a short window (CodeRabbit Major).
- #3239, #3244, #3252, #3268: es/de/cs/zh/ko/ru/pt entries for the new interface strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Nov 3, 2026

Copy link
Copy Markdown
Member

Merged — thank you @hectorviov for the contribution!

I added one review fix on main (865a789): relative R1C1 offsets use checked arithmetic (no overflow on R[9223372036854775807]C) and at most 1024 column-width records are kept, with a regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add support for reading .slk (SYLK) files

3 participants