Free Support Forum - aspose.com

Out of memory exception when copy excel worksheet

Hi,

I'm using in our application Aspose.cells version 7.0.3.0 for creating excel report (based on Excel template)<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

On my code I create an Excel file with 13 worksheets and I copy data into worksheets from an external excel files(one excel file per one worksheet).

When I trying to copy data, the computer's memory is quite busy and the application fails with 'Out of memory' exception. It happens when I use the 'copy' function which copies data from external excel to relevant worksheet.

code:

public static bool GenerateMultiSheetReport(String reportName, String reportFolderName, Dictionary<String,String> templatesMap, List<String> templateList)

{

if (String.IsNullOrEmpty(reportName) || String.IsNullOrEmpty(reportFolderName) || templatesMap == null)

return false;

// Directory does not exist

if(!Directory.Exists(reportFolderName))

return false;

if (templatesMap.Count() == 0)

return false;

//Instantiate a Workbook object that represents Excel file.

Workbook wb = new Workbook();

Worksheet sheet = wb.Worksheets[0];

//Save the Excel file.

wb.Save(reportName);

int index = 0;

foreach (var key in templateList)

{

if (!templatesMap.ContainsKey(key))

continue;

String templatePath = reportFolderName + "\\" + Path.GetFileName(key);

String templateName = templatesMap[key];

if (File.Exists(templatePath))

{

Aspose.Cells.Workbook wbTmp = new Aspose.Cells.Workbook(templatePath);

if (index > 0)

wb.Worksheets.Add(templateName);

else

wb.Worksheets[0].Name = templateName;

if (wb.Worksheets[index] == null)

continue;

wb.Worksheets[index++].Copy(wbTmp.Worksheets[0]);

try

{

File.Delete(templatePath);

}

catch

{

}

}

}

wb.Save(reportName);

try

{

Process.Start(reportName);

}

catch (Exception e)

{

}

return true;

}

Screenshot with exception message and memory usage is attached

Thanks,

Hi,

Thanks for your posting.

Please provide us a simple console application replicating your problem using the latest version:
Aspose.Cells for .NET v7.0.3.4 along with all the source/template excel files. We will look into it and update you asap.

Console application source files and excel templates are attached.

Please extract temp.zip under your C:\ drive and run the application.

Thanks,

Hi,

Thanks for your posting and using Aspose.Cells.

We have done new memory enhancements now.

Please download and try the latest fix:
Aspose.Cells
for .NET v7.3.3.3
. It should fix your issue.

Let us know your run results at your end.