We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Out of memory exception when creating new workbook

Hello,

I am working on a wpf app and I’m using aspose.cells to process excel files.
I’m currently struggling with an out of memory exception.

This is a sample of code showing what I’d like to achieve:

Task.Factory.StartNew(() =>
{
Workbook workbook = new Workbook(filePath);
Workbook template = new Workbook();
template.Copy(workbook);

Worksheet templateSheet = template.Worksheets[0];
templateSheet.Cells.ClearRange(this.configuration.HeaderRow, 0, templateSheet.Cells.MaxRow,
templateSheet.Cells.MaxDataColumn);
string templatePath = string.Format(CultureInfo.InvariantCulture, “{0}\{1}”, this.Configuration.OutputDirectory,
“template.xlsx”);
template.Save(templatePath);

foreach (Staff staff in staffsTemp)
{
Workbook workbookStaff = new Workbook(templatePath, opt);
Worksheet worksheetStaff = workbookStaff.Worksheets[0];
int maxDataRowSourceSheet = workbook.Worksheets[0].Cells.MaxDataRow;
}

})

The exception is thrown at the first construction “Workbook workbook = new Workbook(filePath);”

Thank you for your help.

Regards

@Papotame,

Thanks for the sample code and details.

Please provide us your template Excel file here, we will check it soon. If the file size is more than 20MB, please try some third party services (e.g dropbox, google drive, etc.) to upload the file there and then share the Download link here.

Thank you.

I have solved the issue by calling the dispose function of each workbook when it is not used anymore.

Thank you

@Papotame,

Good to know that you have sorted out your issue now. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.

Thank you.