Search code examples
c#.netexcelepplusclosedxml

How to delete the range of columns in closedXML?


Ive been trying to convert the EPPlus version of functionality into ClosedXML , i was stuck on the line where u send starting column number and total number of columns to delete in EPPlus method like this :

wsData.DeleteColumn(17, wsData.Dimension.End.Column - 18);

ive tried the following in closedXML

var rangeToDelete = wsData.Range(wsData.Column(17).FirstCell(), wsData.Column(34).LastCell());
rangeToDelete.Delete(XLShiftDeletedCells.ShiftCellsLeft);

but it doesnt work , how to solve this ?


Solution

  • Deleting a Range should also work, but if you want to delete whole columns the simpler solution is

    wsData.Columns(17, 34).Delete();