Optimizing Memory Usage while Working with Big Files having Large Datasets

Optimizing Memory

Reading Large Excel Files

The following example shows how to read a large Microsoft Excel file in optimized mode.

Writing Large Excel Files

The following example shows how to write a large dataset to a worksheet in an optimized mode.

Caution

The default option, MemorySetting.NORMAL is applied for all versions. For some situations, such as building a workbook with a large data set for cells, the MemorySetting.MEMORY_PREFERENCE option may optimize memory use and decrease the memory cost for the application. However, this option may degrade performance in some special cases, such as the following.

  1. Accessing Cells Randomly and Repeatedly: The most efficient sequence for accessing the cells collection is cell by cell in one row, and then row by row. In particular, if you access rows/cells by the enumerator acquired from Cells, RowCollection and Row, performance is maximized with MemorySetting.MEMORY_PREFERENCE.
  2. Inserting & Deleting Cells & Rows: Please note that if there are many insert/delete operations for Cells/Rows, the performance degradation will be notable for MemoryPreference mode as compared to the Normal mode.
  3. Operating on Different Cell Types: If most of the cells contain string values or formulas, the memory cost will be the same as Normal mode, but if there are many empty cells, or cell values are numeric, boolean, and so on, the MemorySetting.MEMORY_PREFERENCE option will give better performance.