SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(
newFilePath, true );
var sheet = spreadsheetDocument.WorkbookPart.Workbook
.Sheets.Elements<Sheet>()
.FirstOrDefault();
var sheetReferenceId = sheet.Id;
WorksheetPart worksheetPart = ( WorksheetPart )
spreadsheetDocument.WorkbookPart.GetPartById( sheetReferenceId );
IEnumerable<Row> rows =
worksheetPart.Worksheet.GetFirstChild<SheetData>().Elements<Row>();
foreach ( Row row in rows )
{
int index = ( int ) row.RowIndex.Value + 1;
IEnumerable<Cell> cells = row.Elements<Cell>();
IEnumerable<Cell> cellToDelete = cells.Where( c => string.Compare( c.CellReference.Value, "DD" + index, true ) == 0 );
if ( cellToDelete.Count() > 0 )
{
cellToDelete.First().Remove();
}
}
This code only remove the text from column.But i want to delete the entire column "DD". I am using Open XML SDK for it.