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

Free Support Forum - aspose.com

Replacing microsoft's interop assembly with aspose cells?

Hi,
We are trying to replace existing excel functionality related modules which are using ms interop assembly in our project with aspose cells.

So will be needing some help from your team, i will be posting related questions in the same thread as and when i progress on the conversion.
Hope it helps for others too, to have all the related queries in one thread.

To begin with, i have two questions.

1. In interop, we used to explicitly dispose the objects as it was required. So, in aspose should we need to dispose explicitly by calling any methods ? or it’s already handled by your library?
I guess its been handled, but just wanted to confirm once.
Below is the interop code for your reference.

protected void ExitExcelApplication()
        {
            excelWorkbook.Close(true, missingValue, missingValue);
            excelApplication.Quit();

            excelWorksheet = null;
            excelWorkbook = null;
            excelApplication = null;

            ReleaseObject(excelWorksheet);
            ReleaseObject(excelWorkbook);
            ReleaseObject(excelApplication);
        }
    protected void ReleaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch
            {
                obj = null;
            }
            finally
            {
                GC.Collect();
            }
        }
  1. We have a “Application” class object in interop, which is used for
    a. To start the excel application,
    b. Creating a workbook object and adding worksheets to workbook object
    c. Finally disposing the excel object.
    Hope, these are not required when using apsose, as your “Workbook” object is sufficient to operate with excel workbook. Let us know if you think otherwise.

Also, it has a property “DisplayAlerts”, which is used to control showing of messages when a macro is running in excel. How aspose will handle such a case?
Say for instance: i am writing a value to a cell which has a macro to check whether it’s numeric or text value and showing some message if it’s a text value using a macro implemenation. In this instance, interop suppresses that message by checking DisplayAlerts property, So how aspose will handle the same/similar scenario? Below is the code for your reference.

Application excelApplication = new Application();
    excelApplication.DisplayAlerts = false;

// From microsoft documentation,
// Summary:
// True if Microsoft Excel displays certain alerts and messages while a macro
// is running.
[DispId(343)]
bool DisplayAlerts { get; set; }

@PrathapSV,

Thanks for your queries.

Yes, your understanding is correct. Well, the component (Aspose.Cells for .NET) does not necessarily require really to free up the resources for the processes as the component is already optimized to do so automatically. Aspose.Cells is created in managed C# and is a pure .NET component, we do not use un-managed code. When objects are no more useful in the processes, GC would collect and release the memory occupied by the objects. Being a pure .NET component, Aspose.Cells for .NET relies on .NET garbage collector (GC) to allocate and free the memory for the different processes, although you may try to also use GC.Collect() or try Workbook.Dispose() and set Workbook to null in some cases for your need. Moreover, if you are using Stream objects, you need to call Close() and Flush() methods to manually release the resources for the objects when they are not used.

Yes, your understanding is correct.

I think these are Ms Excel application level settings and does not have any attributes in MS Excel source files (in source xml data), so there is no such property in Aspose.Cells to do the task although you may try to enable or disable macros/vba codes by using the following sample lines of code:
e.g
Sample code:

var settings = workbook.Settings;
settings.EnableMacros = false;

Hope, this helps a bit.