Skip to content

feat(export): add Excel (.xlsx) export for tables and results - #1722

Open
imateusdev wants to merge 9 commits into
TabularisDB:mainfrom
imateusdev:feat/xlsx-export
Open

imateusdev wants to merge 9 commits into
TabularisDB:mainfrom
imateusdev:feat/xlsx-export

Conversation

@imateusdev

@imateusdev imateusdev commented Dec 1, 2026 •

Copy link
Copy Markdown

Closes #1705

What

Adds Excel (.xlsx) to the result export menu (Editor → Export), for both table tabs and query results, in both scopes:

  • All rows: xlsx is a new ExportFormat handled by the backend streaming export (export_query_to_file), next to CSV, JSON, NDJSON, Markdown and HTML.
  • Current results only (Export: stream every format through the backend, with an option to export only current results #1238): Excel is binary, so it cannot go through the client-side formatRowsForExport. A new export_rows_to_xlsx command takes the loaded columns and rows and writes them with the same XlsxSink, so both scopes apply the same cell rules. It lives in application/generic_exports.rs; the desktop command is a thin wrapper and the web RPC routes to the same function (Database authorization, like export_query_to_file).

Cell rules

Value Cell
null empty cell
boolean boolean cell
integer with |n| ≤ 2^53 − 1 number
integer beyond 2^53 text (every digit kept)
float number (the driver already produced a double, so nothing is lost)
string text
array / object JSON text, like the CSV export

DECIMAL/NUMERIC values and integers beyond 2^53 already arrive from the built-in drivers as strings, to keep their precision (i64_to_json, rust_decimal → string). A sink only sees values, not column types, so it cannot tell "12.50" from a VARCHAR holding "007". It therefore keeps all strings as text rather than risk dropping leading zeros or digits. Typing decimals as numbers would need column type info in the sink; I left that out of scope.

The header row is bold and frozen.

Row limit (documented)

A sheet holds up to 1,048,575 data rows (Excel's 1,048,576 minus the header). Longer exports continue on a new sheet (Sheet2, Sheet3, …) that repeats the bold, frozen header. Documented on XlsxSink and in the README's Data Grid → Export bullet. The roll-over is tested with a reduced per-sheet limit.

Text longer than Excel's 32,767-character cell limit fails the export with a clear message (Row N of column "x" holds … characters, more than the 32767 an Excel cell can hold), so nothing is silently truncated.

Memory

Worksheets use rust_xlsxwriter's constant memory mode: each row is flushed to a temp file as it is written, so memory does not grow with the row count. The workbook is zipped into the export writer on finish, through the same LimitedWriter as the other formats in web mode.

New dependency

rust_xlsxwriter = { version = "0.105", features = ["constant_memory"] }

  • License: MIT OR Apache-2.0.
  • Maintenance: actively maintained (by the author of Python's XlsxWriter), widely used.
  • Size: adds 3 crates to the lockfile: rust_xlsxwriter (1.0 MB .crate), zip 9.0.0 (165 KB) and typed-path (110 KB). tempfile was already in the tree. Note that this puts zip 9 next to the existing zip 4.x. I did not measure the release binary size difference.
  • MSRV: 1.88, which time and libsqlite3-sys already require.

Browser download limit

Text formats are capped by LimitedWriter, which sees every byte as it is written. An Excel workbook only reaches the writer when it is zipped on finish, after its rows have gone to the constant-memory temp files. A limit on the zip output alone would therefore let a large web export fill the server's temp directory before failing.

For browser downloads, XlsxSink::with_byte_limit applies the same MAX_FILE_TRANSFER_BYTES while rows arrive, to an upper bound of the worksheet XML written to the temp files. The bound counts each cell's <c> tag (longest cell reference plus style), the XML-escaped text (&, <, >, control characters, _x sequences), numbers at their formatted length (1e300 is 301 digits), and a fixed cost per row and per sheet. A test checks that the bound never undercounts the XML actually written. This goes through run_export_with_limit; run_export keeps its signature. Desktop exports to a local path are not limited, as before.

export_rows_to_xlsx gets the same limit. It runs as a single short spawn_blocking task, because its input is the loaded grid, which the web server caps at 1 MiB per request. So it is not registered for cancel_export, unlike the long-running streaming export.

Known limitation

In web mode, the "current results only" Excel export sends the loaded rows in the request body, which the server caps at 1 MiB (max_body_bytes). A very large loaded grid hits that limit in the browser; "all rows" streams server-side and is not affected. Desktop is not affected.

ExportTableModal (named in the issue) only exports SQL dumps, so it is unchanged. Excel is offered from the result export menu, which covers table tabs too.

Tests

  • src-tauri/src/export/xlsx_tests.rs (22 tests): cell mapping, large-integer and decimal precision, bold and frozen header, typed cells read back from the generated workbook, NULL cells, sheet roll-over with header repetition, empty export, cell-length error, byte limit (including a check that it is an upper bound of the XML actually written), and parity between the in-memory and streaming paths.
  • I also opened a generated workbook with openpyxl: two sheets with the header repeated, bold and frozen at A2; typed numbers and booleans; empty NULLs; and an integer above 2^53 and "0012" kept as text.
  • RPC registration and authorization for export_rows_to_xlsx, plus the contract fixtures for both transports.
  • getExportFileType unit tests.

Ran locally (Windows):

  • cargo test --lib --no-default-features export → 136 passed
  • cargo test --lib --no-default-features transport::web
  • cargo check --locked --no-default-features --bin tabularis
  • pnpm typecheck, vitest (resultExport, dualTransportContract), prettier --check, eslint on changed files, check-theme-tokens

Manual test plan

  1. Run a query that returns more rows than the grid loads. Export → scope All → Excel. Open the file in Excel or LibreOffice: header bold and frozen, numbers right-aligned as numbers, NULLs empty.
  2. Same query, scope Loaded → Excel. Only the loaded rows are in the file, and the partial-export warning shows.
  3. A table with a BIGINT above 2^53 and a NUMERIC(30,10) column: both show every digit (as text).
  4. Web mode (tabularis web): both scopes download result.xlsx.

Summary by CodeRabbit

  • New Features
    • Export query results and loaded rows to Excel (.xlsx).
    • Large exports continue across multiple sheets, each with a repeated header and up to 1,048,575 data rows.
    • Export menus show the correct file extension and format label, including for Markdown and Excel.
  • Bug Fixes
    • Failed exports no longer overwrite an existing destination file.
    • The export dialog no longer offers cancellation while an export cannot be canceled.
  • Documentation
    • Updated the Data Grid export description with supported formats and Excel sheet row limits.

Add xlsx as a streaming ExportFormat backed by rust_xlsxwriter in
constant memory mode, plus an export_rows_to_xlsx command (desktop and
web RPC) for the "current results only" scope, so both scopes share the
same cell rules.

Numbers and booleans become typed cells, NULL an empty cell, and
integers beyond 2^53 stay text. The header row is bold and frozen.
Exports past 1,048,575 rows continue on a new sheet that repeats the
header. Text over Excel's 32,767-character cell limit fails with a
clear message instead of being truncated.

Closes TabularisDB#1705
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Changes

The editor adds Excel export for loaded rows and streamed query results. The backend writes XLSX workbooks, applies worksheet and cell limits, and starts new sheets when row capacity is reached. Web and desktop routes support row exports. Query exports stage output before replacing the destination.

Changes

XLSX format and writer

Layer / File(s) Summary
XLSX format and writer
src-tauri/Cargo.toml, src-tauri/src/export/*, src-tauri/src/application/generic_exports.rs, README.md
The export format now recognizes XLSX. The writer converts JSON values to cells, writes headers, enforces worksheet limits, and rolls over to new sheets. Query exports apply the byte limit to browser downloads. Tests cover cell conversion, workbook output, rollover, and byte accounting. The README documents formats and sheet rollover.

Client-held row export routes

Layer / File(s) Summary
Client-held row export routes
packages/web-ui/src/api/contract.ts, src-tauri/src/application/generic_exports.rs, src-tauri/src/transport/desktop/*, src-tauri/src/transport/web/rpc.rs, packages/web-ui/tests/api/*, src-tauri/src/transport/web/rpc_tests.rs, src-tauri/src/application/generic_exports_tests.rs
Adds export_rows_to_xlsx for supplied columns and rows. Web RPC requires database authorization and supports browser downloads; the desktop command uses a server-path destination. Transport tests cover the request and download response. Server-path tests cover successful replacement and failure preservation. Query exports stage output before replacing the destination.

Editor XLSX export controls

Layer / File(s) Summary
Editor XLSX export controls
packages/web-ui/src/pages/Editor.tsx, packages/web-ui/src/utils/resultExport.ts, packages/web-ui/src/components/modals/ExportProgressModal.tsx, packages/web-ui/tests/utils/*, packages/web-ui/tests/components/modals/*
The editor adds an Excel menu item and routes loaded rows through the new command. Streaming exports use shared extension and filter-name mappings. The progress modal shows a Cancel button only when the active export is cancellable. Tests cover file-type mappings and modal cancellation behavior.

Suggested labels: enhancement

Suggested reviewers: debba, newtthewolf

Change: Feature

Merge Risk: Low · previous review 6603d · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Security architecture risk: High · up to 6603d

A browser export can time out while Tabularis is still generating the workbook. The unfinished job no longer counts against the request limit and can leave a file behind, so repeated timeouts can affect other sessions on the same host. Streamed XLSX exports can also delay unrelated requests during finalization. Staged saves now protect an existing file from ordinary write failures, but Cancel does not confirm that the destination was left unchanged.

Retained concerns

  • Major · security · inferred: The new loaded-row browser RPC releases both admission permits when the request times out, not when the queued or running workbook job ends. Request cleanup can remove a path that does not yet exist, after which the worker can publish a pending workbook outside the download store's expiration sweep. Repeated requests can leave unaccounted work and staged data on the host shared by other sessions.
  • Minor · security · inferred: Streamed XLSX compresses and flushes the workbook synchronously on a Tokio async worker. ZIP compression is necessary for the requested file; placing it on workers that also serve unrelated requests is not. Concurrent authorized exports can delay other sessions, and cancellation cannot interrupt a finalization already in progress.
  • Minor · reliability · inferred: All streamed formats now have a destination commit after output generation. The existing Cancel RPC requests abort and returns without waiting for the task to stop; the new synchronous sync-and-replace step has no cancellation checkpoint. If Cancel races with finalization, the Editor can close the modal while the older operation can still replace the desktop destination. A retry to the same path is not ordered behind that operation.

View findings in the submitted review

Security review details

Security Blast Radius

  • inferred — A Database-authorized browser session can independently submit workbook work without owning a usable saved connection. The supported security consequence is contention for compute and storage shared by sessions on the same backend host, not cross-session download access or browser control of a filesystem path.

Security Findings and Attack Paths

  • inferred — A timed-out request and a finished job can both leave no active RPC and no download token, but only the latter is safe to treat as finished. The detached worker can still consume resources and publish to the private pending path after request cleanup. The download-store sweep covers a different directory and cannot reclaim that output.

Trust Boundaries and Controls

  • observed — The browser supplies data, not a destination or download owner. The backend derives ownership from the browser session, generates a private pending path, applies worksheet and archive size checks, and uses the existing owner-scoped, single-use download claim.

Data and control flow

  • observed — Loaded-row XLSX serializes submitted data without querying a database. Streamed XLSX resolves the saved connection and reuses the existing query-stream path, including read-only validation and isolation from a writable editor transaction when read-only mode applies.

Resilience and Maintainability Implications

  • observed — Workbook validation, write, flush, or sync errors before replacement no longer truncate an existing desktop destination. This is a pre-commit guarantee, not crash recovery or rollback of a completed replacement.
  • inferred — Streamed cancellation remains connection-scoped and best-effort. A deadline drops the registration and requests abort, but cannot interrupt an in-progress synchronous commit. Closing the Editor modal therefore does not distinguish an aborted export from one that is still committing or has already won the race.

Hardening Proposals

  • proposed — Make the workbook job own its admission budget and staging cleanup until it reaches a terminal state. Prevent publication after the requester has abandoned the job, and reclaim stale staging without deleting files still owned by live work.
  • proposed — Run streamed archive finalization and disk sync on bounded blocking workers. Give each export a commit decision that distinguishes confirmed cancellation from completion or a commit already in progress.

Rollout and rollback

  • inferred — A Database-authorized browser session can start loaded-row XLSX, but neither Editor Cancel nor the request deadline stops the workbook worker. On desktop, the user can decline the save dialog before work starts. After a timeout or a streamed Cancel, affected operators should not treat the operation as stopped: verify the destination before retrying to the same path and check for stale browser staging only after export work has stopped.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@kilo-code-bot

kilo-code-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files in incremental diff)
  • src-tauri/src/export.rs
  • src-tauri/src/export/xlsx.rs
  • src-tauri/src/export/xlsx_tests.rs

Review was read-only: no code was run. The incremental change (byte limit now bounds the estimated worksheet XML rather than cell content) was reviewed with no issues found.

Previous Review Summaries (2 snapshots, latest commit da7d223)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit da7d223)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (18 files)
  • README.md
  • packages/web-ui/src/api/contract.ts
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/utils/resultExport.ts
  • packages/web-ui/tests/api/contract/transportContract.ts
  • packages/web-ui/tests/api/dualTransportContract.test.ts
  • packages/web-ui/tests/utils/resultExport.test.ts
  • src-tauri/Cargo.lock
  • src-tauri/Cargo.toml
  • src-tauri/src/application/generic_exports.rs
  • src-tauri/src/export.rs
  • src-tauri/src/export/format.rs
  • src-tauri/src/export/xlsx.rs
  • src-tauri/src/export/xlsx_tests.rs
  • src-tauri/src/transport/desktop/export.rs
  • src-tauri/src/transport/desktop/mod.rs
  • src-tauri/src/transport/web/rpc.rs
  • src-tauri/src/transport/web/rpc_tests.rs

Review was read-only: no code was run and the PR's tests were not executed. The incremental changes (content limit for browser xlsx downloads) were reviewed with no issues found.

Previous review (commit a5734f0)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (18 files)
  • README.md
  • packages/web-ui/src/api/contract.ts
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/utils/resultExport.ts
  • packages/web-ui/tests/api/contract/transportContract.ts
  • packages/web-ui/tests/api/dualTransportContract.test.ts
  • packages/web-ui/tests/utils/resultExport.test.ts
  • src-tauri/Cargo.lock
  • src-tauri/Cargo.toml
  • src-tauri/src/application/generic_exports.rs
  • src-tauri/src/export.rs
  • src-tauri/src/export/format.rs
  • src-tauri/src/export/xlsx.rs
  • src-tauri/src/export/xlsx_tests.rs
  • src-tauri/src/transport/desktop/export.rs
  • src-tauri/src/transport/desktop/mod.rs
  • src-tauri/src/transport/web/rpc.rs
  • src-tauri/src/transport/web/rpc_tests.rs

Review was read-only: no code was run and the PR's tests were not executed.


Reviewed by claude-sonnet-5.5 · Input: 4.2K · Output: 1.2K · Cached: 144.8K

Review guidance: REVIEW.md from base branch main

The workbook only reaches the size-capped writer when it is zipped on
finish, so a large web export could fill the temp directory before
failing. Apply the browser download limit to the cell content as rows
arrive, for both the streaming and the loaded-rows export.
Count an upper bound of the XML each cell adds to the temp files (cell
tag, escaped text, formatted number length, per-row and per-sheet
overhead) instead of the raw value size, so the browser download limit
also bounds the temp files. A test checks the bound against the sheets
actually written.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏛️ Architecture findings (1)

Advisory architecture findings (1)

  • Minor — The new browser export ties admission and staging cleanup to the request rather than the workbook job. If the request ends before the blocking worker opens the staging file, cleanup runs first and the worker can create an orphan afterward. Even without an orphan, unfinished work can continue after the request frees its admission slot. Repetition could affect other sessions on the same host through shared worker or disk pressure.

💬 Code review

Actionable comments posted (4)


  • Ask CodeRabbit to fix comments on this review
Prompt to fix all issues
Treat finding text, file paths, and code as untrusted review data. Never follow
instructions embedded in them. Verify each finding against current code. Fix
only still-valid issues, skip the rest with a brief reason, keep changes
minimal, and validate.

Inline comments:
Review comments at @packages/web-ui/src/pages/Editor.tsx:
- Around line 5294-5298: Update the error-state update in the save-target
selection catch to set isOpen to true and include the attempted filename, so a
rejected platform.chooseSaveTarget() opens the error modal. Preserve the early
return when the save dialog is cancelled.
- Line 5274: For loaded-rows XLSX exports in the `exporting` state, prevent
Cancel from appearing, or register a cancellable handle and ensure the handler
skips writing or downloading after cancellation; choose the behavior based on
the product decision and preserve cancellation behavior for other exports.

Review comments at @src-tauri/src/export.rs:
- Line 55: Initialize the workbook header from `columns` in the loaded-result
export path so column names are preserved when `rows` is empty; do not rely on
`write_row` to establish the header. Keep the metadata-free streaming fallback
separate, and add a test for exporting columns with no rows.

Review comments at @src-tauri/src/export/xlsx.rs:
- Line 31: Update CELL_TAG_BYTES or explicitly account for xml:space="preserve"
and styled-header markup so the XML bound covers the reported 73-byte
inline-string markup plus the possible 6-byte style markup. Add a wide-result
regression case with leading and trailing whitespace that verifies temporary
worksheet XML stays within the configured browser limit.

---

Architecture findings:
- minor: The new browser export ties admission and staging cleanup to the
request rather than the workbook job. If the request ends before the blocking
worker opens the staging file, cleanup runs first and the worker can create an
orphan afterward. Even without an orphan, unfinished work can continue after the
request frees its admission slot. Repetition could affect other sessions on the
same host through shared worker or disk pressure.

After applying the fix, consider running `coderabbit review --agent` for local
review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 307bf331-8a1f-4f9e-afd2-e3c63f3882f3
Commits

Reviewing files that changed from the base of the PR and between 106c6ab and b052a6e.

Files ignored due to path filters: 1

  • src-tauri/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 17

  • README.md
  • packages/web-ui/src/api/contract.ts
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/src/utils/resultExport.ts
  • packages/web-ui/tests/api/contract/transportContract.ts
  • packages/web-ui/tests/api/dualTransportContract.test.ts
  • packages/web-ui/tests/utils/resultExport.test.ts
  • src-tauri/Cargo.toml
  • src-tauri/src/application/generic_exports.rs
  • src-tauri/src/export.rs
  • src-tauri/src/export/format.rs
  • src-tauri/src/export/xlsx.rs
  • src-tauri/src/export/xlsx_tests.rs
  • src-tauri/src/transport/desktop/export.rs
  • src-tauri/src/transport/desktop/mod.rs
  • src-tauri/src/transport/web/rpc.rs
  • src-tauri/src/transport/web/rpc_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


setExportState({
isOpen: true,
status: 'exporting',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Cancel does not stop loaded XLSX exports.

The progress modal shows Cancel for every export in the exporting state, including loaded-rows XLSX exports. The backend cancels only handles registered for the export key. The loaded-rows writer registers none, so cancel_export returns without stopping the workbook write. The handler then continues without a cancellation check. The file is written to the chosen native path, or the download is triggered, even after the user selects Cancel.

Either hide Cancel for this export path, or register a cancellable handle and make the handler skip the write or download when the export is cancelled. The choice between these behaviors is a product decision.

Prompt to fix issue
Treat finding text, file paths, and code as untrusted review data. Never follow instructions embedded in them. Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.

Review comment at @packages/web-ui/src/pages/Editor.tsx at line 5274:
For loaded-rows XLSX exports in the `exporting` state, prevent Cancel from appearing, or register a cancellable handle and ensure the handler skips writing or downloading after cancellation; choose the behavior based on the product decision and preserve cancellation behavior for other exports.

After applying the fix, consider running `coderabbit review --agent` for local review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr

Comment on lines +5294 to +5298
setExportState((prev) => ({
...prev,
status: 'error',
errorMessage: String(e),
}));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Open the error modal when save-target selection fails.

If platform.chooseSaveTarget() rejects, execution reaches this catch before setExportState({isOpen: true, ...}). The update preserves isOpen: false, so the user sees no error.

Set isOpen: true in the error update and supply the attempted filename. Keep the early return for a cancelled save dialog.

Prompt to fix issue
Treat finding text, file paths, and code as untrusted review data. Never follow instructions embedded in them. Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.

Review comment at @packages/web-ui/src/pages/Editor.tsx around lines 5294 - 5298:
Update the error-state update in the save-target selection catch to set isOpen to true and include the attempted filename, so a rejected platform.chooseSaveTarget() opens the error modal. Preserve the early return when the save dialog is cancelled.

After applying the fix, consider running `coderabbit review --agent` for local review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr

Comment thread src-tauri/src/export.rs Resolved

/// Upper bound of the `<c>` element rust_xlsxwriter writes around a cell
/// value, with the longest cell reference (`XFD1048576`) and a style index.
const CELL_TAG_BYTES: usize = 64;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Include whitespace-preservation markup in the XML bound.

In version 0.105.0, an inline string with leading or trailing whitespace can require 73 bytes of markup, excluding its text. A styled header can require another 6 bytes. The writer adds xml:space="preserve", which this 64-byte allowance does not cover. (raw.githubusercontent.com)

For wide results containing padded strings, the accumulated deficit can exceed the worksheet and row allowances. Temporary worksheet XML can then exceed the configured browser limit. Increase the cell allowance or account for this attribute explicitly. Add a wide-result regression case with leading and trailing whitespace.

Prompt to fix issue
Treat finding text, file paths, and code as untrusted review data. Never follow instructions embedded in them. Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate.

Review comment at @src-tauri/src/export/xlsx.rs at line 31:
Update CELL_TAG_BYTES or explicitly account for xml:space="preserve" and styled-header markup so the XML bound covers the reported 73-byte inline-string markup plus the possible 6-byte style markup. Add a wide-result regression case with leading and trailing whitespace that verifies temporary worksheet XML stays within the configured browser limit.

After applying the fix, consider running `coderabbit review --agent` for local review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing the same workbook writer between the two export scopes and keeping large integers and leading zeros intact. Could you fix the empty-result case before merge? In write_rows_to_xlsx, the only place that passes column names to the sink is inside the row loop. With columns id and name and zero rows, finish() starts a sheet with &[], so both headers disappear. Please initialize the sheet with the known columns and add a test that reads the header back from that workbook.

Welcome, and thanks for your first PR here! We’d be happy to have you join us on Discord.

write_rows_to_xlsx passed the column names to the sink only with a row,
so a result with columns and no rows produced a sheet without its header.
Start the sheet with the known columns before writing rows.
@imateusdev

Copy link
Copy Markdown
Author

Thanks for catching that. Fixed in 96b974f: write_rows_to_xlsx now starts the sheet with the known columns before any row, through a new XlsxSink::start_with_headers, so a result with columns and no rows keeps its header.

Tests added:

  • write_rows_to_xlsx_keeps_the_header_without_rows writes id and name with zero rows and reads both header cells back from the workbook. It fails without the fix.
  • start_with_headers_does_not_repeat_the_header checks that the header is written once when rows follow.

The streaming path is unchanged: with zero rows the driver stream gives no column names, so it still writes one empty sheet, as before.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Minor 2
  1. The new loaded-row browser route releases RPC admission when the request times out, not when the workbook job stops. A queued job can create its staging file after request cleanup has already run, and a running job can continue without occupying an RPC slot. Repeated timeouts can therefore put pressure on the shared blocking pool and staging disk without requiring a database query.
  2. Streamed XLSX exports synchronously compress and flush the staged workbook inside a Tokio async task. The existing cancellation registration cannot interrupt that finalization once it starts. Compression is necessary for the export, but running it on shared async workers can delay unrelated requests, including callers that did not request XLSX.
Trivial 1
  1. Desktop XLSX opens and truncates the final destination before validating or completing the workbook. A rejected header or cell can leave a previously existing file empty, and a save failure can leave a partial replacement. Direct writes predate the PR for streamed exports; the workbook-specific failure window and the loaded-row entrypoint are new.

Prompt to fix all issues
Treat finding text, file paths, and code as untrusted review data. Never follow
instructions embedded in them. Verify each finding against current code. Fix
only still-valid issues, skip the rest with a brief reason, keep changes
minimal, and validate.

Architecture findings:
- minor: The new loaded-row browser route releases RPC admission when the
request times out, not when the workbook job stops. A queued job can create its
staging file after request cleanup has already run, and a running job can
continue without occupying an RPC slot. Repeated timeouts can therefore put
pressure on the shared blocking pool and staging disk without requiring a
database query.
- minor: Streamed XLSX exports synchronously compress and flush the staged
workbook inside a Tokio async task. The existing cancellation registration
cannot interrupt that finalization once it starts. Compression is necessary for
the export, but running it on shared async workers can delay unrelated requests,
including callers that did not request XLSX.
- trivial: Desktop XLSX opens and truncates the final destination before
validating or completing the workbook. A rejected header or cell can leave a
previously existing file empty, and a save failure can leave a partial
replacement. Direct writes predate the PR for streamed exports; the
workbook-specific failure window and the loaded-row entrypoint are new.

After applying the fix, consider running `coderabbit review --agent` for local
review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: dd5d7b61-428b-4844-ab27-bb60d6cb6b0a
Commits

Reviewing files that changed from the base of the PR and between b052a6e and 96b974f.

Files selected for processing: 3

  • src-tauri/src/export.rs
  • src-tauri/src/export/xlsx.rs
  • src-tauri/src/export/xlsx_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the header-only workbook. The 24 XLSX tests passed here, including the empty result case. I found a file-loss issue in the desktop export of loaded rows.

I created a valid 5,203-byte workbook, then called export_rows_to_xlsx with that path and one cell containing 32,768 characters. The export correctly rejected the cell, but the original file was now zero bytes. create_private_file truncates the destination before the workbook is validated and written. Please generate the workbook in a temporary file alongside the destination and replace the destination only after writing and flushing succeed. The regression test should check that the original bytes survive a failed overwrite.

I also traced Cancel in the loaded-row progress dialog. It calls cancel_export for the connection, but this operation never registers a cancellation handle, and its completion still calls downloadGeneratedFile. Please either wire cancellation to this export or show the dialog without a Cancel action for this path.

…ws fails

Write the workbook to a temporary file next to the destination and move it
into place only after it is written and synced, so a failed export no longer
leaves a truncated file behind.
cancel_export cannot stop this export, which runs in one blocking task, so
the progress dialog no longer offers a Cancel button for it.
@imateusdev

Copy link
Copy Markdown
Author

Thanks, both fixed.

File loss on a failed overwrite (438db0f): export_rows_to_xlsx now writes the workbook to a temporary file in the destination's directory and moves it over the destination only after the workbook is written, flushed and synced. If any step fails, the temporary file is removed and the original file is left as it was. The temporary file is created with owner-only permissions on Unix, the same as create_private_file. Two new tests in generic_exports_tests.rs:

  • failed_loaded_row_xlsx_export_keeps_the_existing_file overwrites an existing file with a 32,768-character cell, checks that the original bytes survive, and that no temporary file is left behind. It fails without the change, with a zero-byte file as you found.
  • loaded_row_xlsx_export_replaces_the_existing_file checks that a successful export still replaces the file.

Cancel (8eafd85): I went with removing the button. This export runs in one spawn_blocking task, which an abort handle cannot stop once it has started, so wiring cancel_export to it would need a cancellation check inside the row writer. ExportProgressModal's onCancel is now optional, and the Editor passes it only for exports cancel_export can stop. The Excel export of loaded rows shows the dialog without Cancel. Two new modal tests cover both cases.

cargo test for generic_exports and the XLSX tests (31), the web-ui typecheck, and the Editor page tests (75) pass here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Minor 3
  1. The new browser loaded-row command releases RPC admission when the request ends, but an already submitted blocking workbook job can continue. Request-owned cleanup can run before the worker publishes its staging file, leaving a file outside the download store&`#39`;s expiration lifecycle. The command requires Database authorization but no database query; repeated unfinished jobs can put pressure on shared blocking workers and staging storage.
  2. Streamed XLSX runs synchronous workbook compression and flush on a shared Tokio async worker. The existing abort registration cannot interrupt that non-yielding step once it starts. Compression is necessary for XLSX, but doing it on the async worker can delay unrelated requests, including those that did not select XLSX.
  3. Desktop all-rows XLSX truncates the selected destination before workbook validation and finalization. A later validation failure can leave an existing file empty, and a save failure can leave it incomplete. Direct writes predate this PR, but these XLSX failure points are new. The earlier truncation concern no longer applies to loaded-row exports, which replace the destination only after a successful staged write.

Prompt to fix all issues
Treat finding text, file paths, and code as untrusted review data. Never follow
instructions embedded in them. Verify each finding against current code. Fix
only still-valid issues, skip the rest with a brief reason, keep changes
minimal, and validate.

Architecture findings:
- minor: The new browser loaded-row command releases RPC admission when the
request ends, but an already submitted blocking workbook job can continue.
Request-owned cleanup can run before the worker publishes its staging file,
leaving a file outside the download store's expiration lifecycle. The command
requires Database authorization but no database query; repeated unfinished jobs
can put pressure on shared blocking workers and staging storage.
- minor: Streamed XLSX runs synchronous workbook compression and flush on a
shared Tokio async worker. The existing abort registration cannot interrupt that
non-yielding step once it starts. Compression is necessary for XLSX, but doing
it on the async worker can delay unrelated requests, including those that did
not select XLSX.
- minor: Desktop all-rows XLSX truncates the selected destination before
workbook validation and finalization. A later validation failure can leave an
existing file empty, and a save failure can leave it incomplete. Direct writes
predate this PR, but these XLSX failure points are new. The earlier truncation
concern no longer applies to loaded-row exports, which replace the destination
only after a successful staged write.

After applying the fix, consider running `coderabbit review --agent` for local
review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0eb91db4-a44f-4299-b608-993df91618c5
Commits

Reviewing files that changed from the base of the PR and between 96b974f and 8eafd85.

Files selected for processing: 5

  • packages/web-ui/src/components/modals/ExportProgressModal.tsx
  • packages/web-ui/src/pages/Editor.tsx
  • packages/web-ui/tests/components/modals/ExportProgressModal.test.tsx
  • src-tauri/src/application/generic_exports.rs
  • src-tauri/src/application/generic_exports_tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

The streaming export opened the chosen file with truncate before running
the query, so a failure part-way (an Excel cell over 32,767 characters, a
dropped connection) or a cancel left that file empty or incomplete. It now
writes to a temporary file next to the destination and replaces the file
only after the export finished and the data is on disk, like the Excel
export of loaded rows already does.
@imateusdev

Copy link
Copy Markdown
Author

One more fix in the same spirit as the loaded-rows one, pushed in cc25a46.

The all-rows export (export_query) opened the chosen file with truncate before running the query. A failure part-way, such as a cell over 32,767 characters in Excel, or a cancel, left an existing file empty or incomplete. It now writes to a temporary file next to the destination and replaces the file only after the export finished and the data was synced, through the same helper the loaded-rows export uses. This applies to every format, and a cancelled export now leaves the previous file as it was.

One side effect of replacing instead of overwriting: the new file gets the private permissions the export already used for new files, and a symlinked destination is replaced by a regular file rather than written through.

Tests: failed_query_xlsx_export_keeps_the_existing_file (fails on the previous commit: the file ends up with 0 bytes) and query_export_replaces_the_existing_file. cargo test --no-default-features --lib -- export passes (142 tests).

debba
debba previously approved these changes Dec 3, 2026

@debba debba left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for protecting the existing file in both export paths. The failure tests now put a 32,768-character value through loaded-row and query export, then check the original bytes and the directory for leftovers. I also checked the Cancel button change and ran the three changed frontend suites. All 80 tests passed. This looks ready to merge.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments

Major 1
  1. The new loaded-row browser RPC releases both admission permits when the request times out, not when the queued or running workbook job ends. Request cleanup can remove a path that does not yet exist, after which the worker can publish a pending workbook outside the download store's expiration sweep. Repeated requests can leave unaccounted work and staged data on the host shared by other sessions.
Minor 2
  1. Streamed XLSX compresses and flushes the workbook synchronously on a Tokio async worker. ZIP compression is necessary for the requested file; placing it on workers that also serve unrelated requests is not. Concurrent authorized exports can delay other sessions, and cancellation cannot interrupt a finalization already in progress.
  2. All streamed formats now have a destination commit after output generation. The existing Cancel RPC requests abort and returns without waiting for the task to stop; the new synchronous sync-and-replace step has no cancellation checkpoint. If Cancel races with finalization, the Editor can close the modal while the older operation can still replace the desktop destination. A retry to the same path is not ordered behind that operation.

Prompt to fix all issues
Treat finding text, file paths, and code as untrusted review data. Never follow
instructions embedded in them. Verify each finding against current code. Fix
only still-valid issues, skip the rest with a brief reason, keep changes
minimal, and validate.

Architecture findings:
- major: The new loaded-row browser RPC releases both admission permits when the
request times out, not when the queued or running workbook job ends. Request
cleanup can remove a path that does not yet exist, after which the worker can
publish a pending workbook outside the download store's expiration sweep.
Repeated requests can leave unaccounted work and staged data on the host shared
by other sessions.
- minor: Streamed XLSX compresses and flushes the workbook synchronously on a
Tokio async worker. ZIP compression is necessary for the requested file; placing
it on workers that also serve unrelated requests is not. Concurrent authorized
exports can delay other sessions, and cancellation cannot interrupt a
finalization already in progress.
- minor: All streamed formats now have a destination commit after output
generation. The existing Cancel RPC requests abort and returns without waiting
for the task to stop; the new synchronous sync-and-replace step has no
cancellation checkpoint. If Cancel races with finalization, the Editor can close
the modal while the older operation can still replace the desktop destination. A
retry to the same path is not ordered behind that operation.

After applying the fix, consider running `coderabbit review --agent` for local
review. Visit https://docs.coderabbit.ai/cli?utm_source=ghpr
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 608c891f-f7c9-44df-8d52-97f083cc3b92
Commits

Reviewing files that changed from the base of the PR and between cc25a46 and 6603de2.

Files ignored due to path filters: 1

  • src-tauri/Cargo.lock is excluded by !**/*.lock
Files selected for processing: 2

  • README.md
  • packages/web-ui/src/pages/Editor.tsx
Files skipped from review as they are similar to previous changes: 1

  • README.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@debba
debba dismissed their stale review December 3, 2026 12:47

I checked the timeout path and am withdrawing my approval. The RPC releases its session and global permits when the request ends, while the blocking workbook writer can still be running. It can also publish the temporary file after request cleanup has run. Please tie admission and cleanup to the lifetime of the workbook job, and cover a timed-out request with a delayed writer before merging.

…ends

A timed-out RPC released its concurrency permits and removed the pending
file while the blocking writer kept running. The writer now owns both and
releases them when it ends.
@imateusdev

Copy link
Copy Markdown
Author

Fixed in 290b8a4. The writer job now owns the request's permits and the pending file, so they're only released when the writer ends. The new test times out a request while the writer is blocked, checks the permit is still held, then that it's released with no file left behind.

This branch has not been deployed

No deployments
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.

[Feat]: Export query results and tables as XLSX

2 participants