Skip to content

Adds new CopyAndAddSheet API to OpenXmlExporter#965

Merged
michelebastione merged 4 commits into
mini-software:masterfrom
michelebastione:fix-issue-793
May 21, 2026
Merged

Adds new CopyAndAddSheet API to OpenXmlExporter#965
michelebastione merged 4 commits into
mini-software:masterfrom
michelebastione:fix-issue-793

Conversation

@michelebastione
Copy link
Copy Markdown
Collaborator

Due to an internal limitation of the ZipArchive BCL class when instantiated in Update mode, it was not possible to add new worksheets containing big amounts of data using the OpenXmlExporter.Insert method, as this would throw System.IO.IOException (Stream too long).

This new API method works around the problem by copying the contents of an existing Excel document to a new stream or file alongside the new data to add.

Resolves #793.

This allows the insertion huge amount of data into an existing Excel document as the existing Insert method would throw a "Stream too long" exception
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the CopyAndAddSheetAsync API, allowing users to copy an existing OpenXml document and insert or overwrite a worksheet. Significant changes include the addition of OpenXmlWriter.CopyInsert.cs for archive manipulation, refactoring OpenXmlWriter to support update modes, and updating SharedStringsDiskCache for better reliability. Feedback identifies several critical issues, including a bug in the #else block where input and output streams are swapped, thread-safety concerns caused by modifying a static list at runtime, and a typo in a disposal block that prevents a stream from being closed. Additionally, it is recommended to remove an unnecessary seek operation on the input stream.

Comment thread src/MiniExcel.OpenXml/Api/OpenXmlExporter.cs Outdated
Comment thread src/MiniExcel.OpenXml/Writer/OpenXmlWriter.CopyInsert.cs Outdated
Comment thread src/MiniExcel.OpenXml/Writer/OpenXmlWriter.CopyInsert.cs Outdated
Comment thread src/MiniExcel.OpenXml/Writer/OpenXmlWriter.CopyInsert.cs Outdated
Comment thread src/MiniExcel.OpenXml/Api/OpenXmlExporter.cs Outdated
@michelebastione michelebastione merged commit 3f6c894 into mini-software:master May 21, 2026
3 checks passed
@michelebastione michelebastione deleted the fix-issue-793 branch May 21, 2026 21:56
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.

System.IO.IOException: Stream was too long.

1 participant