How to solve the memory leak problem when save excel to html with Aspose.Cells 24.1.0

Please see the demo atthachment, i am building a preview online website with Aspose.Cell 24.1.0, sometimes there is a memory leak problem with a small excel file(file also in demo attachment).
So could you provide a demo project to help solve the following problems:

  1. how to dispose the memory(it could not dispose even call GC.Collect();).
  2. how to interrupt the request, and release the server memory when excute over 3 second.
  3. when there is multi sheets in excel file, how to just load one active sheet and others sheets’s name, then not load other sheet until user click that sheet name?
    Tks.
    AsposeDemo.7z (952.2 KB)

@davidxiao2008,

Thanks for the sample app and details.

I did test your scenario/case using your sample project with Aspose.Cells for .NET v24.7 (please get it and try it: Releases | NuGet). It works fine and I do not see any error or find any significant memory leakage. But, surely, the browser will consume more memory to display the output HTML (having so many records in it). Do you mean the memory of the browser in the which the rendered (output) HTML is shown is increased?

Thanks for you reply.
The server memory will increase to maybe 1GB even when the source file is just 4MB+ when call the document.Save function, and could not release the memory for a long time.
Not memory in client browser memory.
Due to it’s a preview online website and many other user may visit the same file or same problem , Hope it can decrease the server memory as soon as posible and protect the server memory.

Wow, it’s great and reduce a huge save time by v24.7

@davidxiao2008,

Good to know that the suggested version (Aspose.Cells for .NET v24.7) works well for your needs. Please feel free to write back to us if you have further queries or comments.

Thanks for your reply. it’s great with v24.7, i will upgrade to it.
Please help to continue paying attention to these issues and hope to find a solution

@davidxiao2008
1, how to dispose the memory(it could not dispose even call GC.Collect();).
We have created an ticket CELLSNET-56313 for this issue.

2, how to interrupt the request, and release the server memory when excute over 3 second.

3, when there is multi sheets in excel file, how to just load one active sheet and others sheets’s name, then not load other sheet until user click that sheet name?

Thanks for reply.
for point 1, is there a solution can gc by Aspose.Cell v24.7?
for point 2 & 3, please provide a sample netcore project files with ActionResult in MVC, thank you.

@davidxiao2008,

1). We have already logged a ticket with an id “CELLSNET-56313” for the issue. Let us evaluate it in details and then we will be able to either provide a solution or a fixed version.
2) & 3). Please refer to the examples in the suggested documents and then write your own code for your requirements.

hi simon,
for point 3, there is my test code with a demo file( active sheet is [sheetddd], hide sheet is [sheetccc], i got 2 questions need your help.

  1. how can point out the active sheet when CustomLoad, so it can show the content when save as html format.
  2. Can i modify the js function fnSetActiveSheet, so can redirect to another sheet or load another sheet content by ajax when user click.
    demo2.7z (37.6 KB)
        class CustomLoad : LoadFilter
        {
            public override void StartSheet(Worksheet sheet)
            {
                $"sheet: {sheet.Index}-{sheet.Name}, IsSelected: {sheet.IsSelected}, IsVisible: {sheet.IsVisible}".WriteInfoLog();
                if (sheet.Index == ???)
                {
                    // Load everything from worksheet "Sheet2"
                    this.LoadDataFilterOptions = LoadDataFilterOptions.All;
                }
                else
                {
                    // Load nothing
                    this.LoadDataFilterOptions = LoadDataFilterOptions.Structure;
                }
            }
        }

@davidxiao2008
You can use the Workbook.Worksheets.ActiveSheetIndex or Workbook.Worksheets.ActiveSheetName attribute to specify the current active worksheet.

There not exists Workbook.Worksheets.ActiveSheetIndex before load excel file. So i could not use it in CustomLoad

// Load the workbook with the spcified worksheet only.
LoadOptions loadOptions = new LoadOptions(LoadFormat.Xlsx);
loadOptions.LoadFilter = new CustomLoad();

@davidxiao2008
Please refer to the following example code.

class CustomLoad : LoadFilter
{
    public override void StartSheet(Worksheet sheet)
    {
        if (sheet.Index == sheet.Workbook.Worksheets.ActiveSheetIndex)
        {
            Console.WriteLine(sheet.Index + ": " + sheet.Name);
            this.LoadDataFilterOptions = LoadDataFilterOptions.All;
        }
        else
        {
            // Load nothing
            this.LoadDataFilterOptions = LoadDataFilterOptions.Structure;
        }
    }
}

Hope helps a bit.

Thanks John, it works.

@davidxiao2008
Thank you for your feedback. You are welcome. If you have any questions, please feel free to contact us at any time.

Here is another question need help.
Could you give a suggestion how to toggle another sheet and fill with content, when save excel to html format just like my demo : AsposeDemo.7z

@davidxiao2008
You can set up Worksheets.ActiveSheetIndex equals the index of the worksheet that needs to be exported and sets the HtmlSaveOptions.ExportActiveWorksheetOnly is set to true to export only the current active worksheet.

The sample code as follows:

document.Worksheets.ActiveSheetIndex = sheet.Index;

Aspose.Cells.SaveOptions saveOptions = new Aspose.Cells.HtmlSaveOptions
{
    ExportActiveWorksheetOnly = true,
};

Sorry, there is my operation process :
step 1, save excel file as html format and only show active sheet content and other sheets struct with CustomLoadFilter.
step 2, user click other sheet name to toggle sheet, but get a empty sheet content.
So my question is how to fill the other sheet content in step 2.

@davidxiao2008,

Please note, when you only load a specific sheet, other sheets would be discarded and only the name/structures would be retrieved. For your case, you should not load a specific sheet only and instead load all the sheets so that when you click on other sheet tabs, the data would be displayed correctly in the browser.

Moreover, we have already logged a ticket (“CELLSNET-56313”) to address the issue of disposing resources when exporting HTML files, so please wait until the fixed version is published. Hopefully, after using the fixed version, there would be no memory leakage issue.

@davidxiao2008

Please open the file again and again.

 class CustomLoad1 : LoadFilter
        {
            public override void StartSheet(Worksheet sheet)
            {
                if (sheet.Name== “selected”)
                {
                    // Load everything from worksheet "Sheet2"
                    this.LoadDataFilterOptions = LoadDataFilterOptions.All;
                }
                else
                {
                    // Load nothing
                    this.LoadDataFilterOptions = LoadDataFilterOptions.Structure;
                }
            }
        }

After loading the file, then set this worksheet as active and export it to html.
Then replace the old empty html of this worksheet.

BTW after checking convert “demo.xls” to html, we find the main performance issue is converting to html works slow, so you can simply load the file once, then export to html one worksheet by one.