This project has moved. For the latest updates, please go here.

Deleting Ranges

            var workbook = new XLWorkbook();

            var ws = workbook.Worksheets.Add("Deleting Ranges");
            foreach (var ro in Enumerable.Range(1, 10))
                foreach (var co in Enumerable.Range(1, 10))
                    ws.Cell(ro, co).Value = ws.Cell(ro, co).Address.ToString();
            
            // Delete range and shift cells up
            ws.Range("B4:C5").Delete(XLShiftDeletedCells.ShiftCellsUp);

            // Delete range and shift cells left
            ws.Range("D1:E3").Delete(XLShiftDeletedCells.ShiftCellsLeft);

            // Delete an entire row
            ws.Row(5).Delete();

            // Delete a row in a range, shift cells up
            ws.Range("A1:C4").Row(2).Delete(XLShiftDeletedCells.ShiftCellsUp);

            // Delete an entire column
            ws.Column(5).Delete();

            // Delete a column in a range, shift cells up
            ws.Range("A1:C4").Column(2).Delete(XLShiftDeletedCells.ShiftCellsLeft);

            workbook.SaveAs("DeletingRanges.xlsx");

Last edited Sep 20, 2010 at 4:38 AM by MDeLeon, version 1