Skip to content

fix(excel): flush import data to disk and surface write failures - #282

Open
Jeremy6660 wants to merge 1 commit into
iOfficeAI:mainfrom
Jeremy6660:fix/import-persist
Open

fix(excel): flush import data to disk and surface write failures#282
Jeremy6660 wants to merge 1 commit into
iOfficeAI:mainfrom
Jeremy6660:fix/import-persist

Conversation

@Jeremy6660

Copy link
Copy Markdown

Summary

officecli import <xlsx> /SheetN <file.csv> reports success (Imported N rows x M cols into /Sheet1 ...) but writes nothing to the sheet. The xlsx on disk stays empty, so the imported data is silently lost — CSV and TSV both reproduce this.

Root cause

ExcelHandler.Import writes rows/cells into ExcelHandler's in-memory package, but:

  1. SaveWorksheet enqueued the part into _dirtyWorksheets without setting the Modified flag. ExcelHandler.Dispose() therefore treated the whole session as read-only and discarded the in-memory copy (reverted to the on-disk bytes) — the _dirtyWorksheets entries were never flushed.
  2. The import command layer (CommandBuilder.Import) never explicitly saved; it relied on Dispose(), which did nothing because of (1), and reported the returned message string as success regardless.

The set path worked because it goes through the resident/save machinery that does set Modified.

Fix

  • ExcelHandler.Helpers.Sheet.cs: SaveWorksheet now sets Modified = true — a dirty worksheet is itself proof the package was modified, regardless of which caller enqueues it. This is the root-cause fix.
  • CommandBuilder.Import.cs: after handler.Import(...), call handler.Save() explicitly so write-back happens before the success message is printed. Any write-back failure now surfaces as a command error instead of being swallowed on Dispose().

Validation method (per CONTRIBUTING Rule 2)

Before my fix (v1.0.143 baseline):

officecli create t.xlsx
officecli import t.xlsx /Sheet1 data.csv   # → "Imported 3 rows x 2 cols into /Sheet1 starting at A1"
officecli view t.xlsx text                 # → (empty)  ❌ data not present
unzip -p t.xlsx xl/worksheets/sheet1.xml | grep alice   # → (empty)  ❌ on-disk XML has no data

After my fix:

officecli create t.xlsx
officecli import t.xlsx /Sheet1 data.csv   # → "Imported 3 rows x 2 cols into /Sheet1 starting at A1"
officecli view t.xlsx text
# → [/Sheet1/row[1]] A1=name B1=score
# → [/Sheet1/row[2]] A2=alice B2=88      ✓ data present
unzip -p t.xlsx xl/worksheets/sheet1.xml | grep alice   # → present   ✓ on-disk XML has data

Also cross-verified with openpyxl (independent of officecli's own readers): the workbook loaded by a third-party library contains the imported rows after the fix, confirming the bytes were really persisted to disk.

Note: I validated by building the patched source with dotnet build and running the CLI against the compiled officecli.dll (macOS arm64, net10.0.302). CI's multi-platform dotnet build matrix should confirm the same for the other RIDs.

Checklist

  • One atomic change (import data persistence)
  • Compiles clean (dotnet build, 0 errors)
  • Verified data persists to disk (officecli view + unzip XML + openpyxl cross-check)

Import wrote rows into ExcelHandler's in-memory package but never set the
Modified flag on earlier SaveWorksheet enqueues, so Dispose() treated the
session as read-only and discarded the imported data. Set Modified in
SaveWorksheet and call handler.Save() after Import so data is persisted and
write-back failures surface as command errors instead of being swallowed.
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.

1 participant