从c#

时间:2017-08-08 07:38:23

标签: c# excel spreadsheet worksheet-function

     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();
                }
            }

此代码仅从column中删除文本。但我想删除整个列“DD”。我正在使用(Open XML SDK)。任何帮助将不胜感激。谢谢。

0 个答案:

没有答案