/// <summary> /// Insert rows before or aftert current <paramref name="ExcelRangeBase"/> /// </summary> /// <param name="range">current range</param> /// <param name="valuesToInsert">values of each inserted row(same column as current range)</param> /// <param name="copyStyleFromRowIndex">the style of which row should be copied to the new inserted rows</param> /// <param name="Mode">insert mode, before or after</param> /// <param name="columnsToExpand">expand columns for inserted rows. positive for right, negative for left. Default is 0</param> /// <param name="expandValues">values for expanded columns</param> /// <returns></returns> public static void InsertRows(this ExcelRangeBase range, IList valuesToInsert, int copyStyleFromRowIndex, InsertMode Mode, int columnsToExpand = 0, IList expandValues = null) { var rowIndex = range.GetIndex(valuesToInsert, Mode, out int modeValue, columnsToExpand, expandValues); range.Worksheet.InsertRow(rowIndex[0] + ((modeValue + 1) / 2), valuesToInsert.Count, copyStyleFromRowIndex); range.ExpandValue(valuesToInsert, rowIndex, modeValue, Mode, columnsToExpand, expandValues); }