Hi,
I’m using in our application Aspose.cells version 7.0.3.0 for creating excel report (based on Excel template)
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,