简体   繁体   中英

Spreadsheetlight ram usage

I have a issue with SpreadSheetLight. When I use SaveAs method it use about 1.2GB of RAM. I write about 6k records and the output file is only 6MB. Someone else has this issue?

The SaveAs code is here:

using (var stream = new MemoryStream(Templates.BudgetTemplate))
{
    using (var doc = new SLDocument(stream))
    {
        doc.SelectWorksheet("Sheet");

        var i = 2; //first line is header
        var list = new List<object>(); //list initialization from DB Collection

        foreach (var item in list)
        {
            //doc.SetCellValue stuff, from A to AN columns

            i++;
        }

        doc.SaveAs(_path);
    }
}

It's probably to do with file size buffers. Just like running Excel will take up megabytes of RAM just so you can write an 20 kilobyte file, SpreadsheetLight does something similar.

We're talking about Open XML spreadsheets, so technically speaking, the whole set of XML files is held in memory (at save time). For example, when zipping files, you hold the whole text file in memory, and then zip it into a smaller file. This is why SpreadsheetLight (and other libraries) take up more RAM than the final resulting file.

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