简体   繁体   中英

ClosedXML: large Excel file delete column

I am trying to manipulate large excel file using ClosedXML. Its taking infinite time to process. For example.. deleting 10 columns in a 30MB file, never returned! Has anybody else experienced similar issue for ClosedXML. My code is in C#. Below is sample.

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

You should implement "better lambdas" 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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM