internal static void Insert(ExcelRangeBase range, eShiftTypeInsert shift, bool styleCopy) { ValidateInsert(range, shift); var effectedAddress = GetEffectedRange(range, shift); WorksheetRangeHelper.ValidateIfInsertDeleteIsPossible(range, effectedAddress, GetEffectedRange(range, shift, 1), true); var ws = range.Worksheet; lock (ws) { var styleList = GetStylesForRange(range, shift); WorksheetRangeHelper.ConvertEffectedSharedFormulasToCellFormulas(ws, effectedAddress); if (shift == eShiftTypeInsert.Down) { InsertCellStores(range._worksheet, range._fromRow, range._fromCol, range.Rows, range.Columns, range._toCol); } else { InsertCellStoreShiftRight(range._worksheet, range); } AdjustFormulasInsert(range, effectedAddress, shift); InsertFilterAddress(range, effectedAddress, shift); WorksheetRangeHelper.FixMergedCells(ws, range, shift); if (styleCopy) { SetStylesForRange(range, shift, styleList); } InsertTableAddress(ws, range, shift, effectedAddress); InsertPivottableAddress(ws, range, shift, effectedAddress); //Update data validation references foreach (var dv in ws.DataValidations) { ((ExcelDataValidation)dv).SetAddress(InsertSplitAddress(dv.Address, range, effectedAddress, shift).Address); } //Update Conditional formatting references foreach (var cf in ws.ConditionalFormatting) { ((ExcelConditionalFormattingRule)cf).Address = new ExcelAddress(InsertSplitAddress(cf.Address, range, effectedAddress, shift).Address); } InsertSparkLinesAddress(range, shift, effectedAddress); if (shift == eShiftTypeInsert.Down) { WorksheetRangeHelper.AdjustDrawingsRow(ws, range._fromRow, range.Rows, range._fromCol, range._toCol); } else { WorksheetRangeHelper.AdjustDrawingsColumn(ws, range._fromCol, range.Columns, range._fromRow, range._toRow); } } }
internal static void Insert(ExcelRangeBase range, eShiftTypeInsert shift, bool styleCopy) { ValidateInsert(range, shift); var effectedAddress = GetEffectedRange(range, shift); WorksheetRangeHelper.ValidateIfInsertDeleteIsPossible(range, effectedAddress, GetEffectedRange(range, shift, 1), true); var ws = range.Worksheet; lock (ws) { var styleList = GetStylesForRange(range, shift); WorksheetRangeHelper.ConvertEffectedSharedFormulasToCellFormulas(ws, effectedAddress); if (shift == eShiftTypeInsert.Down) { InsertCellStores(range._worksheet, range._fromRow, range._fromCol, range.Rows, range.Columns, range._toCol); } else { InsertCellStoreShiftRight(range._worksheet, range); } AdjustFormulasInsert(range, effectedAddress, shift); InsertFilterAddress(range, effectedAddress, shift); WorksheetRangeHelper.FixMergedCells(ws, range, shift); if (styleCopy) { SetStylesForRange(range, shift, styleList); } InsertTableAddress(ws, range, shift, effectedAddress); InsertPivottableAddress(ws, range, shift, effectedAddress); InsertDataValidation(range, shift, effectedAddress, ws); InsertConditionalFormatting(range, shift, effectedAddress, ws); InsertSparkLinesAddress(range, shift, effectedAddress); if (shift == eShiftTypeInsert.Down) { WorksheetRangeHelper.AdjustDrawingsRow(ws, range._fromRow, range.Rows, range._fromCol, range._toCol); } else { WorksheetRangeHelper.AdjustDrawingsColumn(ws, range._fromCol, range.Columns, range._fromRow, range._toRow); } } }
internal static void Delete(ExcelRangeBase range, eShiftTypeDelete shift) { ValidateDelete(range, shift); var effectedAddress = GetEffectedRange(range, shift); WorksheetRangeHelper.ValidateIfInsertDeleteIsPossible(range, effectedAddress, GetEffectedRange(range, shift, 1), false); var ws = range.Worksheet; lock (ws) { WorksheetRangeHelper.ConvertEffectedSharedFormulasToCellFormulas(ws, effectedAddress); if (shift == eShiftTypeDelete.Up) { DeleteCellStores(ws, range._fromRow, range._fromCol, range.Rows, range.Columns, range._toCol); } else { DeleteCellStoresShiftLeft(ws, range); } FixFormulasDelete(range, effectedAddress, shift); WorksheetRangeHelper.FixMergedCells(ws, range, shift); DeleteFilterAddress(range, effectedAddress, shift); DeleteTableAddresses(ws, range, shift, effectedAddress); DeletePivottableAddresses(ws, range, shift, effectedAddress); //Adjust/delete data validations and conditional formatting DeleteDataValidations(range, shift, ws, effectedAddress); DeleteConditionalFormatting(range, shift, ws, effectedAddress); DeleteSparkLinesAddress(range, shift, effectedAddress); AdjustDrawings(range, shift); } }