Adds new CopyAndAddSheet API to OpenXmlExporter#965
Conversation
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
There was a problem hiding this comment.
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.
Due to an internal limitation of the
ZipArchiveBCL class when instantiated in Update mode, it was not possible to add new worksheets containing big amounts of data using theOpenXmlExporter.Insertmethod, as this would throwSystem.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.