2017-09-04 104 views
0

我想操縱使用ClosedXML的大型Excel文件。它需要無限的時間來處理。例如,刪除30MB文件中的10列,從不返回!其他人是否遇到過與ClosedXML相似的問題。我的代碼是用C#編寫的。以下是樣本。ClosedXML:大型Excel文件刪除列

protected void deleteYears(IXLWorksheet ws) 
    { 
     // Remove columns 
     List<IXLColumn> deletecols = (from p in ws.Rows("6").CellsUsed() 
             where p.Value.ToString().ToUpper().StartsWith("XYZ") 
             select p.WorksheetColumn()).ToList<IXLColumn>(); 
     foreach (IXLColumn x in deletecols) 
     { 
      x.Delete(); 
     } 
    } 

回答

0

你應該實現 「更好的lambda表達式」 https://github.com/ClosedXML/ClosedXML/wiki/Better-lambdas

protected void deleteYears(IXLWorksheet ws) 
{ 
    // Remove columns 
    List<IXLColumn> deletecols = ws 
     .Row(6) 
     .CellsUsed(c => c.Value.ToString().ToUpper().StartsWith("XYZ")) 
     .Select(c => c.WorksheetColumn()).ToList(); 

    foreach (IXLColumn x in deletecols) 
    { 
     x.Delete(); 
    } 
}