Package object was closed and disposed, so cannot carry out operations on this object or any stream opened on a part of this package.

Aug 29, 2012 at 6:27 AM
Edited Aug 30, 2012 at 2:49 AM

Hi All,

I am using following code to write data into excel file:

var newFile = new FileInfo(@"c:\temp\newTest.xlsx");

            var package = new ExcelPackage(newFile);

            // add a new worksheet to the empty workbook
            var worksheet = package.Workbook.Worksheets.Add("Result");
            //worksheet.Cells[1, 1].LoadFromDataTable(ds.Tables[0], false);

            int col = 1, row = 1;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                foreach (object value in dr.ItemArray)
                {
                    worksheet.Cells[row, col++].Value = value;
                }
                if (row == 10000)
                {
                    package.Save();
                }
                row++;
                col = 1;
            }

            package.Save();

When I try to save the data second time, i get "Package object was closed and disposed" error. I am trying to process the data into batch's. Currently in my system, when I try to write more than 8 million cells, I get memory exception. SO I was thinking of writing data into excel in batch's. The idea is to write "N" number of records into excel and then save the file. Is it possible to achieve this behavior?

Editor
Aug 29, 2012 at 11:17 AM
Edited Aug 29, 2012 at 11:18 AM

No, it is impossible and I don´t think partial load/save will be supported soon. ( Maybe never, in my conception, it is a huge refactoring in epplus core, only Jan or Mats can answer this )

Coordinator
Aug 31, 2012 at 6:16 AM

No, I have some plans for memory optimazation, but not partial save/streaming.

If you have a lot of data, make sure you have memory enought, run on a 64 bit system (32 bit limits memory to about 4GB), and of course that you have compiled your component for x64.

Jan

Jul 4, 2013 at 7:34 AM
So it is not possible to save and leave the package open?

If not, the package can not be reopened to write other data?