Workbook.Save(Stream stream, SaveFormat saveFormat) failed if stream does not support Seek

Exception:

System.NotSupportedException:
System.IO.Compression.GZipStream.get_Length()
Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)

Repro code:

        var wb = new Workbook(FileFormatType.Excel97To2003);

        using (var ms = new MemoryStream())
        {
            using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
            {
                wb.Save(gzip, SaveFormat.Excel97To2003);
            }
        }

@evgeny

Thanks for your posting and using Aspose.Cells.

We were able to observe this issue as per your code and description and found the code throws exception on execution. We have logged this issue in our database for product team investigation and for a fix. Once, the issue is resolved or we have some other news for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-45768 - Workbook.Save(Stream stream, SaveFormat saveFormat) fails if stream does not support Seek

C#

var wb = new Workbook();

using (var ms = new MemoryStream())
{
    using (var gzip = new System.IO.Compression.GZipStream(ms, System.IO.Compression.CompressionMode.Compress, true))
    {
        wb.Save(gzip, SaveFormat.Excel97To2003);
        //wb.Save(gzip, SaveFormat.Xlsx);
    }//using
}//using

Exception:

System.NotSupportedException was unhandled
  HResult=-2146233067
  Message=This operation is not supported.
  Source=System
  StackTrace:
       at System.IO.Compression.GZipStream.get_Length()
       at Aspose.Cells.Workbook.Save(Stream stream, SaveOptions saveOptions)
       at Aspose.Cells.Workbook.Save(Stream stream, SaveFormat saveFormat)
       at CellsNet.Program.f1() in F:\Download\Misc\Aspose\NetProjects\AsposeSol\CellsNet\Program.cs:line 208
       at CellsNet.Program.Main(String[] args) in F:\Download\Misc\Aspose\NetProjects\AsposeSol\CellsNet\Program.cs:line 33
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

@evgeny

Thanks for using Aspose APIs.

This is to inform you that we have fixed your issue CELLSNET-45768 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

@evgeny

Thanks for using Aspose APIs.

Please download and try the following latest fix and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-45768) have been fixed in this Aspose.Cells for .NET 17.12 update.

Please also check the following article: