Page tree

Versions Compared

Key

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

...

  • Someone is adding multiple rows into a template file yet is unaware that both InsertRow and InsertRows are legitimate functions (same with InsertColumn(s)).
    Code Block
    /* INCORRECT CODE:
    
    for (int i = 1; i < 50; i++)
    {
         ws.InsertRow(i + 5);
         ws.InsertColumn(i + 5);
    }
    
    */
    Why this method causes issues:
  • Every time a call is sent for InsertRow, InsertRows, InsertColumn, DeleteRow, etc., it requires the updating of the entire grid to calculate the new position of all rows/columns beyond the adjusted ones.
  • Grid updates also require that any formulas that point to something beyond the adjusted position have to be updated to compensate.

...

  • If adding more than just one or two rows, use InsertRows/InsertColumns instead of looping through InsertRow/Column multiple times.
  • InsertRow/Column can still be used, but as grid updates are expensive, they should be retained only for calls of one or two new lines.
    Code Block
    // CORRECT EXAMPLE:
    
    // Example inserting a single row and column to split up data.
    ws.InsertRow(1);
    ws.InsertColumn(1);
    
    // Example inserting multiple rows and columns to move data down.
    ws.InsertRows(0, 10);
    ws.InsertColumns(0, 10);

Avoid Calling AutoFitWidth on a Large Amount of Data

...