diff --git a/src/officecli/CommandBuilder.Import.cs b/src/officecli/CommandBuilder.Import.cs index dc0e5341e..f72de1ddb 100644 --- a/src/officecli/CommandBuilder.Import.cs +++ b/src/officecli/CommandBuilder.Import.cs @@ -113,6 +113,10 @@ private static Command BuildImportCommand(Option jsonOption) ResidentClient.SendClose(file.FullName); using var handler = new OfficeCli.Handlers.ExcelHandler(file.FullName, editable: true); var msg = handler.Import(parentPath, csvContent, delimiter, header, startCell); + // Import works against ExcelHandler's crash-atomic in-memory package. + // Flush before reporting success so write-back failures are surfaced + // as command errors instead of being swallowed by best-effort Dispose. + handler.Save(); if (json) Console.WriteLine(OutputFormatter.WrapEnvelopeText(msg)); else diff --git a/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs b/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs index 9e27ed8ac..9b9859306 100644 --- a/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs +++ b/src/officecli/Handlers/Excel/ExcelHandler.Helpers.Sheet.cs @@ -197,6 +197,12 @@ private static Worksheet GetSheet(WorksheetPart part) => /// private void SaveWorksheet(WorksheetPart part) { + // A dirty worksheet is itself proof that the editable package was + // modified. Keep this invariant here instead of relying on every + // caller to set Modified separately: Import writes rows directly and + // used to enqueue the part without setting Modified, so Dispose() + // treated the session as read-only and discarded the in-memory copy. + Modified = true; _dirtyWorksheets.Add(part); }