We have done an utility method to return a byte[] from an IWorkBook (NPOI).
public static byte[] WorkbookToByteArray(IWorkbook workbook, bool flush = false)
{
using (var ms = new MemoryStream())
{
workbook.Write(ms);
if (flush) ms.Flush();
return ms.ToArray();
}
}
Now we have 2 questions:
- Can we remove the Flush line for the
MemoryStream? There is an using, so perhaps... - How can we free RAM at the end? At the moment, seems that the GC wait to clean the workbook from memory.
EDIT:
More information about RAM situation (the example here is with a very small Excel, about 259KB - to save time, normally we have huge generation of Excel - like 25-30MB or over).

