Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • ExcelApplication fills out everything needed for customization, so when already populated files are passed to it, it requires more for it to load them in than it does for ExcelTemplate alone.
  • Performance affected: Memory and TimeAlso results in a large hit on Time based performance.

Solutions:

  • If the workbook formatting needs to be modified dynamically at runtime, the changes should be made in the unpopulated template before populating the data, rather than to the populated file.
  • Design the template file, load it in ExcelApplication and make any other customizations desired, then pass it on to ExcelTemplate to load in the data.
    Code Block
    // CORRECT CODE:
    
    
    ExcelApplication xla = new ExcelApplication();
    Workbook wb = xla.Open(Page.MapPath(@"path\to\code.xlsx"));
    
    /*...*/
    
    ExcelTemplate xlt = new ExcelTemplate();
    
    xlt.Open(xla, wb);
    
    xlt.Process();
    xlt.Save(Page.Response, "Completed.xlsx", false);
    

...

  • Forces ExcelWriter to create cell (and associated) object(s) for each cell referenced.  For large quantities of unnecessary cells, this can quickly result in performance issues.
  • Performance affected: Memory

Solutions:

  • Don't vaguely guess how much area a data set might take, try to narrow down the area as much as possible towards only populated data.
  • Start with the range of populated cells so you are only looping through theirs.

...

  • Just clearing out the values and formatting does not mean the cell has been removed.  ExcelTemplate does not overwrite existing cells while passing values into the template file, it just pushes them down.
  • Template files that previously had lots of values that are not properly cleaned out quickly become bloated.
  • Performance affected: Memory

Solutions:

  • Identify blank cells.  This can be done by hitting ctrl+f, then pressing the button 'Find All'.  This will return a list of all cells which currently exist in the file. (If there is a large number of cells, this may take a while.)
  • Delete any rows/columns which contain empty cells.  Note: The scrollbars may not change after deleting the rows, the best way to check is by saving and re-opening the file.
  • Don't apply formatting to ranges of blank cells; instead apply it to either just cells with data markers or to column and row headers.
  • If all else fails, start over and create a new, blank, template file. 

...

  • Styles set to areas still apply to each individual cell.
  • When styles are set on individual cells, the a copy of the style information is kept for every one of the cells. 
  • When styles are set on rows/columns, only one copy of the information is kept for each row/column.
  • Performance affected: Memory

Solutions:

  • Apply styles to large numbers of cells by setting the style to either rows/columns or to singular data marker cells.
  • If more than one style is needed in a row/column, and it can't be handled by switching the style for the other (ie, setting style on a row to change part of a column), try to keep the style that takes a majority of the row/column as the one set by that row/column.

...

  • DataTables create an in-memory copy of all the data.  They are useful for manipulating data in memory or updating the database, but tends to be rather inefficient for just pulling data out of a database.
  • Performance affected: BothAlso results in a hit on Time based performance.

Solutions:

  • DataReader is more efficient at pulling out data and displaying it, as it just reads one row at a time out of the database and doesn't keep anything in memory.
  • DataTables still have uses beyond those provided by DataReader, so sometimes they are still needed to filter, sort or otherwise manipulate the data before populating the workbook.

...