In my projects, I am currently dealing with extremely large Excel files, and I encounter an “OutOfMemory” exception when attempting to copy the content of a workbook into a memory stream. My approach involves reading a large Excel file into a workbook, using the MemoryPreference setting, and subsequently saving it to a memory stream. The challenge arises when the workbook itself exceeds 1 GB, and it’s copied to the memory stream using the workbook.Save() method. Is there a way to directly reference the internal stream of the workbook, if such a stream exists? This would help me avoid excessive memory consumption.
Thanks for your message. I’ve already read the full page there and have applied what’s discussed. But it did not help me. I need to save workbook in a memory stream and I don’t want to double my memory consumption while doing it.
When you are loading and saving a large Excel file (e.g., 1GB in size), the process itself will require a huge amount of memory and consume more CPU power. Unfortunately, there is no better way to cope with this issue. Even if you could open such a large Excel file manually in MS Excel, it would still take more time and memory to finally open the file. Nonetheless, please try using our latest version of Aspose.Cells for .NET (if you are not already using it). Additionally, if possible, try using the light weight mode provided by Aspose.Cells, if it is appropriate/feasible for your scenario, this can give you better performance.
In any case, if you still encounter any significant performance issues, kindly provide us with a sample Excel file (you may create a smaller version of the larger Excel file) and sample code. We will promptly evaluate your issue.
@DNolf
And there is no such kind of stream in workbook model. Most of the data of the workbook needs to be instantiated as object of corresponding type for user’s convenience and performance consideration. If you do not need to modify any data of the workbook, then you do not need to open and re-save the workbook to memory stream. You can just load the byte data of the template file into the memory stream, later you can instantiate the workbook from the memory stream whenever you need. If you need to change some data and then re-save the workbook, we are afraid there is no such a solution to save the memory significantly. If it possible, we think instantiating the memory stream with a proper size to avoid expanding the buffer repeatedly may be helpful for memory cost.