public static IXLRange MoveRange(IXLRange range, IXLCell cell) { if (!IsCellInsideRange(cell, range)) { IXLRange newRange = CopyRange(range, cell); range.Clear(); return(newRange); } // If the cell which the movement occurs to is inside the range then the way above will not work properly, // That's why, copy through the auxiliary sheet IXLWorksheet tempWs = null; try { tempWs = AddTempWorksheet(range.Worksheet.Workbook); IXLRange tempRange = range.CopyTo(tempWs.FirstCell()); range.Clear(); return(tempRange.CopyTo(cell)); } finally { tempWs?.Delete(); } }
public static IXLRange CopyRange(IXLRange range, IXLCell cell) { IXLCell newRangeFirstCell = cell; IXLCell newRangeLastCell = ShiftCell(newRangeFirstCell, new AddressShift(range.RowCount() - 1, range.ColumnCount() - 1)); IXLRange newRange = range.Worksheet.Range(newRangeFirstCell, newRangeLastCell); if (!IsCellInsideRange(cell, range)) { newRange.Clear(); range.CopyTo(newRange); } else { // If the cell which the copy occurs to is inside the range then the copy will be wrong (copying is performed by cells, // copied cells appear in the first range immediately and start copying again) // That's why, copy through the auxiliary sheet IXLWorksheet tempWs = null; try { tempWs = AddTempWorksheet(range.Worksheet.Workbook); IXLRange tempRange = range.CopyTo(tempWs.FirstCell()); newRange.Clear(); tempRange.CopyTo(newRange); } finally { tempWs?.Delete(); } } return(newRange); }
public static void DeleteRange(IXLRange range, ShiftType type, XLShiftDeletedCells shiftDirection = XLShiftDeletedCells.ShiftCellsUp) { switch (type) { case ShiftType.Cells: range.Delete(shiftDirection); break; case ShiftType.Row: if (shiftDirection == XLShiftDeletedCells.ShiftCellsUp) { range.Worksheet.Rows(range.FirstRow().RowNumber(), range.LastRow().RowNumber()).Delete(); } else { range.Worksheet.Columns(range.FirstColumn().ColumnNumber(), range.LastColumn().ColumnNumber()).Delete(); } break; case ShiftType.NoShift: range.Clear(); break; } }