2014-03-04 65 views
1

刪除列我有以下方法通過使用刪除使用「的Microsoft.Office.Interop.Excel」如何從Excel中使用的OpenXML

public static void DeleteExcelColumn(ref Microsoft.Office.Interop.Excel.Worksheet objSheet, List<int> deleteColumns) 
    { 
     Microsoft.Office.Interop.Excel.Range objCols = objSheet.Columns; 
     Microsoft.Office.Interop.Excel.Range objCol = null; 
     foreach (int column in deleteColumns) 
     { 
      objCol = (Microsoft.Office.Interop.Excel.Range)objCols[column,Type.Missing]; 
      objCol.EntireColumn.Delete(Microsoft.Office.Interop.Excel.XlDeleteShiftDirection.xlShiftToLeft); 
     } 

     System.Runtime.InteropServices.Marshal.ReleaseComObject(objCols); 
     System.Runtime.InteropServices.Marshal.ReleaseComObject(objCol); 
    } 

我如何達到同樣從Excel列「的OpenXML 「從這個站點

public static void DeleteExcelColumnUsingOpenXML(ref DocumentFormat.OpenXml.Spreadsheet.Worksheet objSheet, List<int> deleteColumns) 
{ 
     SheetData sheetData = objSheet.GetFirstChild<SheetData>(); 
     foreach (int column in deleteColumns) 
     { 
      sheetData.Elements<DocumentFormat.OpenXml.Spreadsheet.Columns>() ??? 
      // delete column 
     } 
} 

回答